We needed to show a given text on some of our blog posts because they contained useful php code snippets.
Our users can hire us to potentially customize the snippets for them.
We've just added a tag called "snippets" to the posts that have at least one snippet.
The code below checks if a post has it and our desired text will be displayed.
Make sure you edit this snippet and replace "ENTER-YOUR-TAG-HERE" with the tag of your choice.
We're using this snippet as a system plugin (installed in wp-content/mu-plugins/)
<?php // Hook into the_content add_filter('the_content', 'orb_render_text_cta', 100); /** * Code downloaded from https://orbisius.com/p4298 * @param string $content * @return string * @see https://wordpress.stackexchange.com/questions/51732/what-filters-are-applied-to-the-content-function */ function orb_render_text_cta($content) { if (empty($_SERVER['REQUEST_URI'])) { return $content; } if ( is_singular() && is_main_query() && has_tag('ENTER-YOUR-TAG-HERE') ) { $content .= ""; $content .= "Some text to be shown if the current post has a given tag"; $content .= ""; } return $content; }
Do you need any of the code in this post customized or packaged into a plugin? Get a free quote
Referral Note: When you purchase through a referral link (if any) on this page, we may earn a commission.
If you're feeling thankful, you can buy me a coffee or a beer