My site's url is set up to include www in settings -> general. I also put it at the very top of my functions.php:


However, when I use the get_template_directory_uri(); function it outputs the non-www URL when enqueuing stylesheets. Any ideas on why this may be happening?

for example, in functions.php

wp_register_style('main-css',  get_template_directory_uri() . '/css/main.css', array(), '1.0', 'all');


<link rel='stylesheet' id='main-css-css'  href='http://federal-lawyer.com/material/themes/fedlaw/css/main.css?ver=1.0' type='text/css' media='all' />

Interestingly, this doesn't happen for scripts enqueued in the functions.php file.

$java_script_url = get_template_directory_uri().'/js/';
wp_register_script('flex_slider', $java_script_url.'flexslider/jquery.flexslider-min.js', array('jquery'), '2.2.0', true);
  • do you have any plugins or theme code which may be filtering style_loader_src or style_loader_tag? – Milo Dec 27 '13 at 2:09
  • 1
    It cannot output one thing in one place and another thing in another place without something else changing between the two. So if it's doing something different for scripts vs. styles, then you have code elsewhere that is altering it in between those two cases. – Otto Dec 27 '13 at 13:37

Setting the siteurl and home should be done in wp-config.php.

  1. Remove them from functions.php.
  2. Add the below into wp-config.php (making sure they don't already exist).

    define( 'WP_HOME', 'http://www.federal-lawyer.com' );

    define( 'WP_SITEURL', 'http://www.federal-lawyer.com' );

  • The OP is using update_option in functions.php not define, but yes, the values should be defined in wp-config.php or set in the backend, not updated halfway through the WordPress boot. – s_ha_dum Dec 27 '13 at 15:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.