Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

If I have built a site using an existing theme (i.e. "Twenty-Ten"), but then modified it considerably and want to re-name it entirely, how would I go about doing this without breaking all the links? I know I can simply text-edit the style.css to change the name there, but I'm referring to the root all throughout the install:

<link rel='stylesheet' href='http://myWebsite.com/wp-content/themes/CURRENTTHEMENAME/styles/style.css" />

to ....

<link rel='stylesheet' href='http://myWebsite.com/wp-content/themes/NEWTHEMENAME/styles/style.css" />
share|improve this question

1 Answer 1

up vote 5 down vote accepted

You should never use <link> tags for stylesheets. Always use the proper API functions:

Better practice Example:

function wpse57423_register_stylesheets()
{
    wp_enqueue_style( 
        'themes_main_stylesheet'
        get_stylesheet_directory_uri()."/style.css"
        array() // Use this array if you've deps that need to load before your stylesheet
        filemtime( get_stylesheet_directory()."/style.css" )
    );
}
function wpse57423_enqueue_stylesheets()
{
    wp_enqueue_style( 'themes_main_stylesheet' );
}
// Add to public page
add_action( 'wp_enqueue_scripts', 'wpse57423_register_stylesheets' );
add_action( 'wp_enqueue_scripts', 'wpse57423_enqueue_stylesheets' );
// Add to login
add_action( 'login_enqueue_scripts', 'wpse57423_register_stylesheets' );
add_action( 'login_enqueue_scripts', 'wpse57423_enqueue_stylesheets' );
// Add to admin UI/backend
add_action( 'admin_enqueue_scripts', 'wpse57423_register_stylesheets' );
add_action( 'admin_enqueue_scripts', 'wpse57423_enqueue_stylesheets' );

Please note that the login page needs specific treatment. Refer to this answer if you need to handle it.

This allows to

  • enqueue/register styles only where you need them and don't load them everywhere
  • child themes the possibility to override your styles with adding a stylesheet with a) the same name in b) the same position in their folder
  • deregistering stylesheets in child themes
  • unhooking the functions
share|improve this answer
    
Sorry for my confusion, but where would I place this code? And would this code allow me to change the name of my theme? –  mcranston18 Jul 4 '12 at 20:49
    
A) In your functions.php file OR a plugin B) Yes. The path is dynamic inside those functions. They use the dir structure constants of the WP filesystem, that you've set (or not set and therefore they're still default) inside your wp-config.php. –  kaiser Jul 4 '12 at 21:49
    
Thanks for your help Kaiser. So I would: add the the code above into my functions.php file (does it matter where?), change my theme name within my style.css, and change the root-name of my theme (i.e. wp-content/themes/newNameForTheme), and I should be good to go? –  mcranston18 Jul 5 '12 at 12:55

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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