WordPress.org

Ready to get started?Download WordPress

Forums

Stylesheet not changing from the default on certain pages (4 posts)

  1. CBjornsen
    Member
    Posted 1 year ago #

    Hi guys.
    This is my first wordpress site, so what I am missing is possibly something simple.
    I have trouble changing stylesheets when on certain pages.
    I have tried every possible solution there is to be found on this forum, however none of them turned out to be working for me.

    What I have found to be the best solution is by using conditional tags in the head section of the site - at least that is how most of the problems have been solved for others.

    The theme I am using is one I have built up on my own.

    This is my entire <head> section

    <head>
    	<?php if ( is_page(101) ) { ?>
    	<link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>/page-facelift.css" type="text/css" media="screen">
    	<?php } else { ?>
    	<link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css" media="screen" />
    	<?php } ?>
    <?php wp_head();?>
    </head>

    I have no idea what I am missing, probably something simple. Any ideas?
    I have also tried using several plug-ins to do the job, however, none of them has any effect. (Tried Stylesheet Per Page, Per Post Scripts & Styles, Custom CSS for Posts and Pages (CCSS))

    The site can be seen here: click

    Regards, CBjornsen

  2. keesiemeijer
    moderator
    Posted 1 year ago #

    Try it with this [untested]:

    <?php if ( is_page(101) ) { ?>
    	<link rel="stylesheet" href="<?php echo get_stylesheet_directory_uri(); ?>/page-facelift.css" type="text/css" media="screen">
    	<?php } else { ?>
    	<link rel="stylesheet" href="<?php echo get_stylesheet_directory_uri(); ?>/default.css" type="text/css" media="screen">
    	<?php } ?>

    Change "default.css" to the stylesheet name you use for all other pages.

    http://codex.wordpress.org/Function_Reference/get_stylesheet_directory_uri

  3. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    http://codex.wordpress.org/Function_Reference/bloginfo

    stylesheet_url       = http://example/home/wp/wp-content/themes/child-theme/style.css

    'stylesheet_url' is for the output of the full link to style.css;

    in here:
    <link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>/page-facelift.css" type="text/css" media="screen">

    possibly use 'stylesheet_directory';

    or rewrite the line to:

    <link rel="stylesheet" href="<?php echo get_stylesheet_directory_uri(); ?>/page-facelift.css" type="text/css" media="screen">

    http://codex.wordpress.org/Function_Reference/get_stylesheet_directory_uri

  4. CBjornsen
    Member
    Posted 1 year ago #

    It worked! That is amazing. Thank you guys so much!! You probably saved me a few more days of trying out the same solutions over and over again. :-)

    The solution I went with is the:
    <link rel="stylesheet" href="<?php echo get_stylesheet_directory_uri(); ?>/page-facelift.css" type="text/css" media="screen">

    Works like a charm!

    Again, thank you guys so much!

    cheers!

Topic Closed

This topic has been closed to new replies.

About this Topic