• Resolved timsig

    (@timsig)


    Hello,
    I have two pages that I want to link to a custom stylesheet. The customer care page is based on a template, and the single-5.php is a custom single post page. The first links perfectly, the second not at all. I can’t understand why, as the code is almost identical:

    <?php if (is_page_template('customerCare_template.php')) {?>
        <link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/css/customerCare.css">
        <?php }?>
    
        <?php if (is_page('single-5.php')) {?>
        <link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/css/customerCare.css">
        <?php }?>

    Thanks for any help.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Check out the is_page() function reference. That function isn’t looking for a php file name. It’s looking for an ID, a slug, a title, or an array of any of those. So if your page has an ID of 5, you’d want to use is_page( 5 );.

    Thread Starter timsig

    (@timsig)

    Thanks for the reply; since this is not a page listed in the dashboard, but a php file called by the theme, I found the easiest way round it was to link to the stylesheet from the file itself, rather than from the header.

    In case you didn’t already know, you can tie into the header code from (just about) anywhere by adding an action. Your code in the “single-5.php” file would be this:

    <?php
    add_action( 'wp-head', 'single-5-style' );
    function single-5-style { ?>
       <link rel="stylesheet" href="<?php bloginfo( 'template_url' ); ?>/css/customerCare.css">
       <?php
    }

    Thread Starter timsig

    (@timsig)

    Thanks for that; I love a learning curve.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Linking to custom CSS file’ is closed to new replies.