Using an Alternate CSS based on page.ext
-
Hey all,
I have a site running a custom store outside of the wordpress installation, within a custom template using Twenty Twelve.
I have a certain CSS style running on the main pages (darker background, etc ..) and when a user navigates into the product pages, I would like to use an alternate stylesheet. I have researched the codex and registered the new stylesheet in my functions.php file, and then made calls in to the header to listen for the page, and based on criteria, load the new css if there is a match. (in this case, if page = products.php, load different css sheet.) Here is my code below, which isnt erroring out, but it is never loading in the new stylesheet. It loads the default sheet everytime.
Functions.php
—————–function theme_styles() { wp_register_style( 'styleP', get_template_directory_uri() . '/styleP.css', array(), '20130227', 'all' ); // enqueing: wp_enqueue_style( 'styleP' ); } add_action('wp_enqueue_scripts', 'theme_styles');
Header.php
—————–function curPageName() { return substr($_SERVER["SCRIPT_NAME"],strrpos($_SERVER["SCRIPT_NAME"],"/")+1); } $ppage = curPageName(); // echo $ppage . "<br />"; if ( $ppage == 'products.php' ) { ?> <link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/styleP.css" type="text/css" media="screen" /> <?php } else { ?> <link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css" media="screen" /> <?php }
- The topic ‘Using an Alternate CSS based on page.ext’ is closed to new replies.