Build Your Own Business Website header image

Syntax Error in Conditional Statement – if(is_page())

Difficulty Level -

Filed Under Topics - , ,

Listed Under Lesson Subjects -

Whoops, you've found some premium content!

Watch the opening clip of this video to preview it,
the full video is available to paid members.

A member used some suggested code on the forum to remove the H1 tag from a specific page.  She discovered that the code worked fine if the conditional statement used the page slug but did not work if using the page id.  We discovered the syntax error that led to the problem of the page id version not working.

Video Transcript

When we are working on the no headline area function, when you pasted the page number in, it didn’t work. But when you typed in the slug, it did.” Okay so Kathy and I were looking this let’s see… let’s go to my dashboard and find it. On the forum here, we are looking at yeah, how to write a function. And so she’s got a filter here to eliminate the headline. So the headline no longer shows and so she used a filter that Girlie published which should have worked fine. What she wanted to do then though was add additional pages to it and… “when you typed the slug, it did but when you typed in the page id number, it didn’t”. Well, you could try putting quotation marks around the page id number. Let’s just look at an example of this on my site.

Let’s see… and we’ll go to Category archives. We’ll go to Templates. Yeah, you know, I don’t use quotation marks around my numbers so you should be able to say “if is page array” and then just string a group of numbers like that together with a comma and a space and that should work without any difficulty. If we look up this on the codex, WordPress conditional tags…if we looked this up on the codex and it says “if is page”… well, you know what? Maybe if it’s a single one, it does need to be inside single quotation marks. Maybe that’s the right answer for this. And if it is page array, then it doesn’t necessarily need to be inside the quotation marks.

You know, generally speaking, the page id number is a more reliable method of identifying the post and say, the post’s slug because it can be the case since you know, inadvertently have duplicate post slugs. But you can… but if it’s page 42 or in your case, 1909, maybe I would suggest is putting it inside single quotation marks and see if it works. Otherwise, it should work fine. So try that and then let me know back.

0 Comments… add one

Save $200 on Membership Now!

Start learning today for as little as
$0.82 PER DAY!
Subscription Options
0 comments… add one