0

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" />

1 Answer 1

5

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
3
  • Sorry for my confusion, but where would I place this code? And would this code allow me to change the name of my theme? Commented Jul 4, 2012 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
    Commented Jul 4, 2012 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? Commented Jul 5, 2012 at 12:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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