• Resolved qph9697

    (@qph9697)


    Hi,

    I want to add my ‘AdSense ad” in “before_the_main_content” GP Hook.

    I referred your documentation and found this PHP code,

    add_action( ‘your_hook_name’,’example_function_name’ );
    function example_function_name() { ?>
    Insert your hook contents in here.
    <?php }

    But this adds the AdSense code on all pages including HOMEPAGE.

    I referred your conditional hooks tags documentation,
    https://docs.generatepress.com/article/using-hooks-conditional-tags/#blog-posts-page

    But the issue is, how will I combine

    add_action( ‘your_hook_name’,’example_function_name’ );
    function example_function_name() { ?>
    Insert your hook contents in here.
    <?php }

    AND
    This

    <?php if ( ! is_front_page() ) : ?>
    This content is EXCLUDED from the static front page
    <?php endif; ?>

    I have no PHP coding knowledge

    My “before_the_main_content” code will look something like this,

    add_action( ‘your_hook_name’,’example_function_name’ );
    function example_function_name() { ?>
    <div align=”center”>
    <ins class=”adsbygoogle”
    style=”display:inline-block;width:xxpx;height:xxpx”
    data-ad-client=”ca-pub-xxxxxxxxxxxx”
    data-ad-slot=”xxxxxxxxxx”>
    <script>
    (adsbygoogle = window.adsbygoogle || []).push({});
    </script>
    </div>
    <?php }

    I DON’T want this to run on my HOMEPAGE.
    Please help me with this.

    Thank You.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hi there,

    this is how the Conditional Hook will look:

    add_action( 'your_hook_name','example_function_name' );  
    function example_function_name() {
    
        if ( ! is_home() ) : ?>
    
            // Insert your hook contents in here.
            
        <?php endif;
    
    }
    Thread Starter qph9697

    (@qph9697)

    Hi, this it worked!!

    if ( ! is_home() ) : ?>

    The “home()” didn’t(ads were still visible on the homepage) but when I replaced it with “front_page()”, it worked.
    Thanks!!

    Hey Hi have one question,

    Does GP hooks also work for amp pages??

    I am using ampforwp plugin.

    Is there any relation between generatepress theme and the amp pages?

    • This reply was modified 4 years, 9 months ago by qph9697.
    Theme Author Tom

    (@edge22)

    Hi there,

    Yes, hooks should still work on AMP pages.

    The only thing you want to be careful of with AMP pages is adding too much CSS/any javascript. Things like HTML in hooks are perfectly compatible.

    Let me know if you have any other questions ??

    Thread Starter qph9697

    (@qph9697)

    Thank You for the reply.

    Theme Author Tom

    (@edge22)

    No problem ??

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Issue with GP Hooks’ is closed to new replies.