简体   繁体   中英

Wordpress/PHP: if () {} not working with is_page()

This is a WP template made from scratch.

I have this inside the head :

    <?php

    if (is_page(about-contact)) {
        $cssDirectory = get_stylesheet_directory_uri();
        echo "<link rel='stylesheet' href='" . $cssDirectory . "/scss/onepage-scroll.css'/>";
    } else {
        echo '';
    }

    ?>

There is another on like this for a script at the bottom of the body .

However, it is behaving as if it is always true for every page I have made a template. The only one not pulling the css and script php lines is the blog page, that has no template on it.

How can I make it work for one single page (page-home.php, in this case)?

is_page() requires an integer, string, or array as input. In your case, it looks like you want to provide the slug of the page, which should be in quotes:

if (is_page('about-contact')) {...

If you're trying to detect the front page, use is_front_page() instead of is_page()

Source: is_page() , is_front_page()

Hugo I think you just made grammar error. You should use

is_page('about-contact')

Instead of:

is_page(about-contact)

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