- This topic has 11 replies, 3 voices, and was last updated 8 years, 4 months ago by
Tom.
-
AuthorPosts
-
November 28, 2017 at 4:58 pm #437423
Scott
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
November 28, 2017 at 5:28 pm #437441Leo
StaffCustomer SupportHi there,
Can you try this?
<?php if ( is_front_page() ) : ?> code here <?php endif; ?>Keep in mind that this is for static front page.
November 28, 2017 at 5:46 pm #437448Scott
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 ?
November 28, 2017 at 5:51 pm #437451Leo
StaffCustomer SupportIs your front page the blog page?
November 28, 2017 at 5:55 pm #437454Scott
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.
November 28, 2017 at 6:08 pm #437461Leo
StaffCustomer SupportTry 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
November 28, 2017 at 7:05 pm #437487Scott
i tried that already i’m afraid. It does not work/make any difference. The code within if statement always runs.
November 28, 2017 at 7:08 pm #437489Tom
Lead DeveloperLead DeveloperIf 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.
November 28, 2017 at 7:26 pm #437495Scott
I’m afraid that doesn’t work either. Even page 2 still thinks is_home == true.
November 28, 2017 at 7:47 pm #437499Tom
Lead DeveloperLead Developeris_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; ?>November 28, 2017 at 8:22 pm #437512Scott
OK great thank you. Worked that time.
November 28, 2017 at 8:26 pm #437514Tom
Lead DeveloperLead DeveloperYou’re welcome 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.