Archived topic
Prevent a Hook from showing in Preview
3 replies · Started by Frank on February 23, 2021
Hello all,
I use Elements to add a hook for a code snippet and set the display rule to posts only. The code is designed to import content wherever it's embedded so for the most part this is the best setup.
However, is there a way to prevent this hook from being loaded in a preview of a post? The code snippet I'm using would wind up importing the preview/draft of the post as well, so it needs to be excluded somehow from previews and ONLY appear in published posts. Any help appreciated!
Hi Frank,
Unfortunately I don't believe this is possible. The preview function is from WordPress itself so the theme has no control over it.
If this is absolutely needed, I would recommend checking with WordPress support team to see if there is way to prevent something from showing in preview.
If they somehow have something built-in for that, then we might be able to make it work.
I was able to figure it out, basically use Elements, enable PHP and use the following line:
<?php if ( ! is_preview() ) { ?>
<!-- code snippet -->
<?php } ?>
That ensures the code will not load in previews using GP Elements.
Glad to hear :)