admin管理员组

文章数量:1295875

I've had the same code on my wordpress site for more than a year, and it's stopped working. This is part of page.php:

<?php
if (is_page( 83571 )) { 
  include('adsense-schools.php');
} else { 
  include('adsense.php');
}
?>

Previously, this used to work, but today I noticed that it is not working correctly. adsense.php is included on all other pages, but adsense-schools.php does not show on page 83571. (And I have checked to make that sure that page id didn't change, the URL when editing that page ends in ...wp-admin/post.php?post=83571)

I also tried changing to page title instead of page id number, so

<?php
if (is_page( 'international-schools' )) { 
  include('adsense-schools.php');
} else { 
  include('adsense.php');
}
?>

But that didn't work either. Am I missing anything?

I've had the same code on my wordpress site for more than a year, and it's stopped working. This is part of page.php:

<?php
if (is_page( 83571 )) { 
  include('adsense-schools.php');
} else { 
  include('adsense.php');
}
?>

Previously, this used to work, but today I noticed that it is not working correctly. adsense.php is included on all other pages, but adsense-schools.php does not show on page 83571. (And I have checked to make that sure that page id didn't change, the URL when editing that page ends in ...wp-admin/post.php?post=83571)

I also tried changing to page title instead of page id number, so

<?php
if (is_page( 'international-schools' )) { 
  include('adsense-schools.php');
} else { 
  include('adsense.php');
}
?>

But that didn't work either. Am I missing anything?

Share Improve this question edited Apr 7, 2021 at 16:09 Lina asked Apr 7, 2021 at 13:46 LinaLina 112 bronze badges 7
  • is_page() is for front-end use, not use in the admin panel. Might be easier to just check against $_GET['post'] – Howdy_McGee Commented Apr 7, 2021 at 14:32
  • Sorry, I should have specified that this is in page.php – Lina Commented Apr 7, 2021 at 16:08
  • And you're certain that 83571 is a post type = page and not a post or some other post type? – Howdy_McGee Commented Apr 7, 2021 at 16:29
  • 1 Yes. When I go to edit at the top it says "Edit Page" and not "Edit Post." – Lina Commented Apr 7, 2021 at 23:15
  • have you checked that adsense-schools.php still exists and is unchanged? – Michael Commented Apr 8, 2021 at 0:16
 |  Show 2 more comments

1 Answer 1

Reset to default 0

If nothing else works you can alternatively try the following:

global $post;

<?php if( $post->ID == 83571) { ?>

      include('adsense-schools.php');

<?php } ?>

本文标签: phpIf ispage includeelse not working all of a sudden