Archived topic
GP Hooks is_front_page() not working
11 replies · Started by Scott on November 28, 2017
Hi
I am using latest GP Pro and WP versions. For some reason when i try to use the following code in GP Hooks it always tells me i'm on front page.
Used within 'Inside Content Container' hook.. Execute PHP is selected, it is not disabled.
<?php
$isfront = is_front_page();
echo "Is front page: " . $isfront ? "true" : "false";
?>
Regardless of page it always prints true. My goal is to only show some shortcodes on front page.
thanks
Hi there,
Can you try this?
<?php if ( is_front_page() ) : ?>
code here
<?php endif; ?>
Keep in mind that this is for static front page.
Hi, it doesn't work i'm afraid. I'm not really sure what you mean by static page.. i am using the GP Blog system. I would like to selectively show content only on page 1. How can this be done in PHP via GP Hook please ?
Is your front page the blog page?
yes, i think so at least. It's local dev or i would show you but in "Settings>Reading>Your homepage displays" is using "Your latest posts" option. And when i access the blog the first page is the blog.
Try this instead:
<?php if ( is_front_page() && is_home() ) : ?>
code here
<?php endif; ?>
More info here: https://codex.wordpress.org/Conditional_Tags#The_Main_Page
i tried that already i'm afraid. It does not work/make any difference. The code within if statement always runs.
If your home page is the blog, you can do this only:
<?php if ( is_home() ) : ?>
Your stuff in here
<?php endif; ?>
This will only work if the "Execute PHP" checkbox is checked.
I'm afraid that doesn't work either. Even page 2 still thinks is_home == true.
is_home() would be true even if it's page 2.
To target the first page, you would have to do this:
<?php
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
if ( is_home() && 1 == $paged ) : ?>
Content in here
<?php endif; ?>
OK great thank you. Worked that time.
You're welcome :)