Archived topic
Hide "After content hook" in category pages.
5 replies · Started by Anastasios on January 30, 2018
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?

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?
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.
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; ?>
Thank you Tom.
No problem :)