I have several posts where part of the displayed content will depend on several conditions. I am thinking on creating a custom html tag. Then, before displaying the post content, the conditions will be checked by running a script in the background . Finally the appropriate content will be displayed by replacing the tag with data retrieved from a database.

What is the best way to do this pre-processing with wordpress? Are they specific hooks allowing to get access to the post before displaying it?



custom html



1 Answer 1


If you're using the classic editor, then a custom shortocode is a good option. Although shortcodes can be used with the block editor the more modern way would be to create a custom (dynamic) block.

You can insert the shortcode / block to the post content when needed and have the callback handle any necessary logic and rendering.

If you prefer, you could also use the_content filter, which lets you modify the post's content, as a string, before it is rendered - assuming you're using the_content() in your Loop or otherwise applying the filter to the post content.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.