Relative path instead of absolute for wp_enqueue_script


When you enqueue scripts or styles with the following:

function themeslug_enqueue_style() {
    wp_enqueue_style( 'core', '/style.css', false ); 
add_action( 'wp_enqueue_scripts', 'themeslug_enqueue_style' );

You get the following:

<link rel='stylesheet' id='core-css'  href='http://localhost:8080/wordpress/style.css?ver=4.9.4' type='text/css' media='all' />

Note that it appends the site url to the beginning, in this case http://localhost:8080. I’m trying to remove this so that it’s relative to the file executing this. Usually this is done with plugins_url or get_stylesheet_uri(). However, I DO NOT want to use either of these, as it may be used as a plugin or included in the theme – and I want to keep the code the same for both.

Is there a way to do this?

, , , Troy Templeman 5 years 2018-03-23T08:26:15-05:00 0 Answers 95 views 0

Leave an answer