• Harvinder Singh Sharry

    (@sufi-punjabi-shayar)


    Hi,

    I’m doing some kind of optimization in which I have to load “custom CSS” code in the head of every page.

    But the issue is that I have to load different CSS code for the different page. For example
    _______________________
    For is_front_page

    <style id=”above-the-fold-css”>
    Custom CSS1
    </style>

    ____________________________
    For is_archive

    <style id=”above-the-fold-css”>
    Custom CSS2
    </style>

    _________________________
    For is_search

    <style id=”above-the-fold-css”>
    Custom CSS2
    </style>

    _______________

    To load Custom CSS in the head of all the post, i’m using this code

    add_action(‘wp_head’,’et_custom_style_for_post’);
    function et_custom_style_for_post(){

    $output = ”;
    if(is_singular( ‘post’ )){
    $output .= ‘<style id=”above-the-fold-css”>

    Custom CSS
    }
    echo $output;
    }

    and adding this code in the funcation.php file

    I hope you get my point. lol

    ——————————————————
    Now, come to the point!

    i need a code to load custom CSS in the head of

    is_font_page
    is_page
    is_archive
    is_Catogery
    is_tag
    is_search
    is_single

    thanks in advance

Viewing 4 replies - 1 through 4 (of 4 total)
  • Renu Sharma

    (@renusharma23july)

    Below code should work for you.

    <?php if ( is_front_page() ){ ?>
    <style id=”above-the-fold-css”>
    Custom CSS1
    </style>
    <?php } elseif ( is_page( ’14’ )) { ?>
    <style id=”above-the-fold-css”>
    Custom CSS2
    </style>
    <?php } elseif ( is_archive()) { ?>
    <style id=”above-the-fold-css”>
    Custom CSS3
    </style>
    <?php } elseif ( is_category( ‘1’ )) { ?>
    <style id=”above-the-fold-css”>
    Custom CSS4
    </style>
    <?php } elseif ( is_tag(‘hentry’)) { ?>
    <style id=”above-the-fold-css”>
    Custom CSS5
    </style>
    <?php } elseif ( is_search()) { ?>
    <style id=”above-the-fold-css”>
    Custom CSS6
    </style>
    <?php } elseif ( is_single()) { ?>
    <style id=”above-the-fold-css”>
    Custom CSS7
    </style>
    <?php } ?>

    Thread Starter Harvinder Singh Sharry

    (@sufi-punjabi-shayar)

    <?php if ( is_front_page() ){ ?>

    <style id=”above-the-fold-css”>
    Custom CSS1
    </style>

    <?php } ?>

    may just copy this in a function.php file ?

    Renu Sharma

    (@renusharma23july)

    Copy it in header.php

    Thread Starter Harvinder Singh Sharry

    (@sufi-punjabi-shayar)

    ok, give me some time to check this.

    thanks for the help.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Load code in the header of catogery, tag, archive page’ is closed to new replies.