[Resolved] GP Hooks is_front_page() not working

Home Forums Support [Resolved] GP Hooks is_front_page() not working

Home Forums Support GP Hooks is_front_page() not working

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #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

    #437441
    Leo
    Staff
    Customer Support

    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.

    #437448
    Scott

    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 ?

    #437451
    Leo
    Staff
    Customer Support

    Is your front page the blog page?

    #437454
    Scott

    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.

    #437461
    Leo
    Staff
    Customer Support

    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

    #437487
    Scott

    i tried that already i’m afraid. It does not work/make any difference. The code within if statement always runs.

    #437489
    Tom
    Lead Developer
    Lead Developer

    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.

    #437495
    Scott

    I’m afraid that doesn’t work either. Even page 2 still thinks is_home == true.

    #437499
    Tom
    Lead Developer
    Lead Developer

    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; ?>
    #437512
    Scott

    OK great thank you. Worked that time.

    #437514
    Tom
    Lead Developer
    Lead Developer

    You’re welcome 🙂

Viewing 12 posts - 1 through 12 (of 12 total)
  • You must be logged in to reply to this topic.