Hugo Moutinho
Hugo Moutinho

Reputation: 103

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)?

Upvotes: 1

Views: 1045

Answers (2)

Spartacus
Spartacus

Reputation: 1508

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()

Upvotes: 1

Dmitriy Buteiko
Dmitriy Buteiko

Reputation: 644

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

is_page('about-contact')

Instead of:

is_page(about-contact)

Upvotes: 1

Related Questions