the_content filter
-
Hi I am trying to add a piece of content before every post (which requires running a short code) on the single post page. I am trying to use the_content filter in the child functions.php like the below. However it doesnt seem to run. Nothing happens. Even removing the short code to run a simple line of text doesn’t work. The theme uses wp bakery page builder for the post pages, so not sure if this affects the filter?
Appreciate any ideas on how to make the content appear automatically above each blog post. Ideally without altering the theme to avoid issues on updates. Current code is below:
TIAfunction my_content_filter($content){
//only add text before WordPress posts
if(is_single() && is_main_query()){
$before = do_shortcode( '[runMyShortcodeHere][myShortcodeEnds]' );
//modify the incoming content
$content = $before . $content ;
}
return $content;
}
add_filter( 'the_content', 'my_content_filter' );
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
The topic ‘the_content filter’ is closed to new replies.