Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I want to check if current page match at least one of two conditions. I don't want to show js code into about page and into 404 page. For the rest of my pages i show the js code. So, I use ((!is_page(element1) AND !is_page(element2)) then show the js code. Element1 is a slug of one specific page and element2 is 404.php page. I don't know the slug or name of 404 page to indicate in if statement.

share|improve this question
1  
I don't get how a page could be a template element1.php and a 404 page in the same time ? It's one or the other - 404 is by definition a 'ressource not found' so it does not use any template but the 404.php template. –  Simon Feb 5 '13 at 22:21
    
I need a trigger that works if any of two conditions match. I display a search form for each page only if it is not a main page or if it is not a 404 page where other search form is included in body. my new code works well for my blog –  Yurij73 Feb 5 '13 at 22:32
1  
"if any of two conditions match" = ORstatement. –  Simon Feb 5 '13 at 22:39
1  
Your description is inconsistent with the accepted answer, which has been edited (by you, @Yurij73) since @Simon published it. You say you want "at least one of two conditions" to match, but the answer requires both conditions to match. That is an ||, as @Simon originally had it, not an &&. This is going to lead to a lot of confusion. Please clean up the question. –  s_ha_dum Feb 5 '13 at 22:39
    
Exactly as @Simon say 0 for any of two condition. That was a cible. I'm correcting my question now to expose question in a right way. –  Yurij73 Feb 6 '13 at 4:54
show 1 more comment

2 Answers

up vote 1 down vote accepted

I think this would do :

if ( is_page( 'element1.php' ) || is_404() ) {
// do that  if page is using template page element1.php or is 404
}
share|improve this answer
add comment

A 404 page probably doesn't have a slug. It is created automagically like the tag and category pages archive pages

Now, is_page doesn't tell you anything about the template being used, which you seem to be thinking about checking for when you say and "and element2 is 404.php page". is_page_template will. So...

if (is_page('element1') || is_page_template('404.php')) {
  // stuff
}

Will trigger if page-slug == element1 is loaded or if a page is loading that uses 404.php. But 404.php is not a necessary theme file so looking for the template may not be what you want. You probably want to use is_404 as in Simon's answer (which you should "accept" if you go with is_404).

share|improve this answer
    
thanks for your, so detailed answer. it is useful for me! –  Yurij73 Feb 5 '13 at 22:17
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.