0

i want from my footer.php file some part like <div class="form">----------</div> this part will be visible all page but not show in home page and few other other. i think it is possible via use php condition.

i read is_home, and is_front_page conditional problem but that way not also work

<?php if ( !is_home() && !is_front_page() ) {
echo "Hello World";
} else {

echo "Else World";
}
?>

for all page even home page i am getting Hello World. i tried <?php if ( ( is_page('home')) ) { also <?php if ( ( is_home() || is_front_page() ) ) { also <?php if(is_page(248)){

not work.

0

You want to "reverse" your logic, in a sense. You need "not (home or front)", not "not home and not front". For example:

// var_dump(is_home(),is_front_page(),(is_home() || is_front_page()),!(is_home() || is_front_page())); // debug
if ( !(is_home() || is_front_page()) ) {
  echo "Hello World";
} else {
  echo "Else World";
}

An easier, more readable way to write the same thing is:

if ( is_home() || is_front_page() ) {
  echo "Else World";
} else {
  echo "Hello World";
}

Please be aware that theis_home() and is_front_page() functions can be confusing.

| improve this answer | |
  • thank u so much. i tried both your code. copy and paste to footer.php.. home page and all other other page i am getting Hello World. very much confusing – pagol001 May 21 '15 at 17:37
  • Uncommented the var_dump line. Do you ever get a true for worker is the first two values? – s_ha_dum May 21 '15 at 18:26
  • home page and rest of page i am getting this message bool(false) bool(false) bool(false) bool(true) Hello World – pagol001 May 21 '15 at 18:52
  • So neither is_home() nor is_front_page() ever returns TRUE. Something about the way your theme is built (or a lugin in interfering) is causing problems. Your code will never work until you figure out why. That is, you need to figure out the page logic of your theme before you will be able to get done what you want to do. I can't guess at what that logic is. – s_ha_dum May 21 '15 at 18:59
  • The code I posted, by the way, works on my test install with a bundled Twenty-something theme. – s_ha_dum May 21 '15 at 18:59
1

You can use page id as mentioned by @vee s answer. For Eg: If you want to echo Hello world on front page, page id 1, and 2 with echo Else world for all other pages, use:

<?php 
if ( ( is_front_page() ) && ( is_page(1) || is_page(2) ) ) {
    echo "Hello World";
} else {
    echo "Else world";
?>

For more info: https://codex.wordpress.org/Function_Reference/is_page

| improve this answer | |
0

Use this.

<?php 
if ( (!is_front_page() ) && (is_page (14) || is_page(25) || .... ) ) 
{
    echo "Hello World";
} 
?>
| improve this answer | |
  • it work <?php if ( (!is_front_page() ) && (is_page (92) ) ) { echo "Hello World"; } ?> but it only effect on home page and 92 id. mean hello world don't show in home page but show in 92 page and rest of page not show. i want home not show and 92 not show and rest of page will show. – pagol001 May 21 '15 at 9:54
  • Okay, In that case just put ! before for the you want to hide. Like : <?php if ( (!is_front_page() ) && (!is_page (92) || .. other pages to hide ) ) { echo "Hello World"; } ?> This process is lengthy, instead of this you can create two page templates and select from admin, or you can create the form in sidebar and display/hide the sidebar using this plugin wordpress.org/plugins/display-widgets Using the hard coded way is not recommended, thus page template or option is recommended. Share your thoughts – Vee May 21 '15 at 11:17
0

Put all the page Ids in an array for which you do not want to show the div. Try the following code.

global $post;
$posts_array = array(1);
$current_page_id = $post->ID;

if ( (! is_front_page() ) && (  ! in_array( $current_page_id, $posts_array ) ) ) {
    echo "Hello World";
} 
| improve this answer | |
  • i have more than 195 pages. it hard put all page id thats why i want like this way – pagol001 May 21 '15 at 10:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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