• I have my local WordPress installation on vagrant. When I share local domain via ngrok it does not load styles and scripts due to absolute path. Is there a way to make wp_enqueue_style and wp_enqueue_script generate relative path instead of absolute?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hello there,

    There are two main WP functions to use to find the relative paths within a theme:

    get_template_directory()

    get_template_directory_uri()

    Thread Starter qwazzy

    (@qwazzy)

    Yes, but how do I make wp_enqueue_style and wp_enqueue_script generate <style> and <script> tags with relative urls instead of absolute? When I pass relative url to wp_enqueue_style/script it comes out absolute. For example:

    wp_enqueue_style( 'my-theme-style', get_theme_file_uri('/assets/css/theme.css'), array(), null, 'all' );

    generates this tag in the <head>:

    <link rel='stylesheet' id='my-theme-style-css' href='https://mysite.test/wp-content/themes/mytheme/assets/css/theme.css' type='text/css' media='all' />

    What I’m looking for is to make it generate href with relative url, like this:

    <link rel='stylesheet' id='my-theme-style-css' href='/wp-content/themes/mytheme/assets/css/theme.css' type='text/css' media='all' />

    • This reply was modified 6 years, 10 months ago by qwazzy.
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to make wp_enqueue_scripts generate relative path?’ is closed to new replies.