WordPress is_page() Oddity

is_page(’about’) didn’t work but is_page(’9′) was fine”

Any of you out there who gets into customising WordPress would likely be aware of the is_page() function. This one is a simple way of asking if it’s a certain page do something or else do an alternate something. It’s not really rocket science but I had an odd bug happen with it today worth sharing.

It appeared that for some reason when I had been passing the URI across as ?page_id=about and ?page_id=archives I couldn’t get a sensible response from is_page(’about’) or is_page(’archives’) for the life of me. While is_home() worked fine. Anyway debugging was a bit of an interesting trail.

dịch vụ seo uy tín seochat.vn I did notice that either the about or archives page still showed the page title to be archives regardless. Clue number one. I checked wp_title() and sure enough that stayed on archives either way. The cure was simply to pass the page numbers instead of their names - ?page_id=9 and ?page_id=11 - and use is_page(’9′) and is_page(’11′).

And I can’t positively say why this is so either so if you know then fill us all in here. Its just another coding oddity in the backfiles now.

Update: 4/9/05
I had to rebuild that same page today from scratch due to a slip of the cut and paste and behold now the same page works with is_page(’archives’) and not is_page(’11′) which just goes to show that something I’ve been modifying in the PHP has trodden on icky ground.

Comments are closed.