[Resolved] Hide "After content hook" in category pages.

Home Forums Support [Resolved] Hide "After content hook" in category pages.

Home Forums Support Hide "After content hook" in category pages.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #483686
    Anastasios

    Hi. Thanx for the great job you do here.
    I use in “after content hook” a shortcode for related posts. I would like this shortcode to display only in single posts. So i use:
    `<?php if ( is_single() ) : ?> [*shortcode*] <?php endif; ?>
    but the code is displayed in post categories archive.
    I also tried to hide hook in a specific categoy-id but it was also displayed.
    Any help?

    screenshot

    #483744
    Leo
    Staff
    Customer Support

    Hi there,

    If you’ve used is_single() then it shouldn’t display in posts archives.
    https://docs.generatepress.com/article/using-hooks-conditional-tags/#single-posts

    Can you double check if execute PHP is checked?

    #483773
    Anastasios

    Hi Leo.

    I had checked “Execute PHP” but didn’t work.
    Also it was displayed: DISALLOW_FILE_EDIT is defined. You should also disallow PHP execution in GP Hooks".
    due to the security plugin i use.
    So, i added define( 'GENERATE_HOOKS_DISALLOW_PHP', true ); in wp-config below define( 'DISALLOW_FILE_EDIT', true ); and after that checkbox was hidden.

    #483979
    Tom
    Lead Developer
    Lead Developer

    Adding this will disable PHP in hooks completely – you’ll want to remove it if you need PHP in them:

    define( 'GENERATE_HOOKS_DISALLOW_PHP', true );

    As for code, try this:

    <?php if ( is_single() ) : ?>
        <?php echo do_shortcode( '[your-shortcode]' ); ?>
    <?php endif; ?>
    #484242
    Anastasios

    Thank you Tom.

    #484635
    Tom
    Lead Developer
    Lead Developer

    No problem 🙂

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