• 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:

    TIA

    function 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)
  • Moderator threadi

    (@threadi)

    Works fine for me with TwentyTwentyOne as theme and without WPBakery. Try it in a page on your site without this PageBuilder. If it doesn’t work there either, it’s because of your theme – which one are you using?

    Thread Starter creativ3y3

    (@creativ3y3)

    Hmm thinking it might be the theme then, just used the classic editor with no luck, theme is Unicon – Design-Driven Multipurpose Theme

    I guess its a case of new theme or try to ask developer if there is a way to use the filter with the theme?

    Or is there a different solution to produce the same results?

    Moderator threadi

    (@threadi)

    As your theme is a commercial theme, you would have to contact their support: https://themeforest.net/item/unicon-designdriven-multipurpose-theme/10648488/support – questions about commercial products cannot be answered here in the forum.

    The alternative is always to use a different theme.

    Theoretically, it is also possible to customise the single.php file for a classic theme, preferably using a child theme, see: https://developer.ww.wp.xz.cn/themes/advanced-topics/child-themes/ – you would have to ask their support if this is possible with your current theme.

    Thread Starter creativ3y3

    (@creativ3y3)

    No problem, understood. As a generic question relating to the structure of wordpress files and child themes, if the single.php template is able to be used in a child theme (by say copying it into the child theme folder). Does this “over-ride” the existing one in the theme, meaning if the theme single.php file gets updated the child one wont? Where if you can do it by plugin or child functions.php it would’nt over-ride the whole file as such…

    Moderator threadi

    (@threadi)

    meaning if the theme single.php file gets updated the child one wont?

    Yes. If the parent theme get an update the child theme wont be touched.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘the_content filter’ is closed to new replies.