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.

I've been using Wordpress for a while, and came to a point where I need to make css customizations, but only for a certain page. I know that one way to do this is to use conditional tags:

if ( is_page( 'mypage' )

And that's where I get stuck!

Are there any other ways of making css customizations, only for a certain page?

share|improve this question
    
conditional tags to edit css — that's not very clear. But you can have a CSS file load only on a specific page, if that's what you want –  its_me Jun 30 '12 at 11:22
    
does your theme use body_class() in the body tag (in header.php ?) ? –  Michael Jun 30 '12 at 12:50
    
Any progress on this (or your other) question(s)? –  kaiser yesterday

2 Answers 2

If you have a lot of rules that you need to conditionally apply (there's no hard and fast rule, but, to make one up, maybe 10-15+ lines?) then @aahan's answer is the way to go. If you only have a few though, just work off body class.

In your header.php file (that's the common name at least) make sure the <body> has:

<body <?php body_class(); ?>>

Then you'll get lots of classes you can use to write conditional styles like

.page-123 .entry-content
.template-my-custom-template-php h1

etc...

share|improve this answer

You'd need something like this (to be added in functions.php):

add_action('wp_enqueue_scripts','wpse57014_register_script');
function wpse57014_register_script(){

    //Register and enqueue stylesheet only on this page
    if ( is_page( 'mypage' ) ) {
        wp_register_style( 'wpse57014_mypage_stylesheet', get_template_directory_uri().'/mypage-style.css' );
        wp_enqueue_style( 'wpse57014_mypage_stylesheet' );
    }

}

Where mypage is the slug of the page on which ONLY you want to load the stylesheet. Replace instances of mypage in the code to keep the code understandable to you (or modify it as you wish, if you know what you are doing).

get_template_directory_uri().'/mypage-style.css' is the path to the stylesheet in your theme, for example — http://example.com/wp-content/themes/MY THEME/mypage-style.css.

share|improve this answer
    
Thanks! I'll try that! :D –  Nick Jun 30 '12 at 11:33

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.