简体   繁体   中英

if home css for wordpress

css conditioning if user is in homepage of wordpress?

I put this

<?php if(is_home()) {
echo '<link rel="stylesheet" href="customHome.css">'
} ?>

into my page editor and it did applied the css. but because it's using echo so there will be some bug. it echo out some thing like

> echo ' ‘ } ?>

in the end of the post.

I want to know where else should I include that? I tried to put in header but it doesn't work.

You can append css by using wp_enqueue_scripts like;

function custom_css() {
    if (is_home()) {
        wp_enqueue_style( 'custom_style_name', 'path_to_your_css' );
    }
}

add_action( 'wp_enqueue_scripts', 'custom_css' );

Put above code block to functions.php

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM