Support » Plugin: Reusable Text Blocks » add_filter(‘the_content’, ‘my_function’) alters textblocks

  • Hello!

    I need to add the same content to the end of each post. So I try to use custom function in functions.php similar to this:

    function the_end( $text ){
    	return $text . ' The end!';
    }
    add_filter('the_content', 'the_end');

    But text appears not only at the end of each post, but also inside the post after each textblock inserted with a shortcut.

    How to solve this?

    Thanks in advance!

Viewing 2 replies - 1 through 2 (of 2 total)
  • So what function should I use to distinguish posts only?

    in_category($category) and is_single() don’t work.

    Mentioned functions return true.

    • This reply was modified 3 months, 2 weeks ago by corvex.
    • This reply was modified 3 months, 2 weeks ago by corvex.
    • This reply was modified 3 months, 2 weeks ago by corvex.
    • This reply was modified 3 months, 2 weeks ago by corvex.

    @corvex : I had the same problem. Specifically using Jetpack sharing & related posts features. They append to the content using the the_content filter. So my reusable text blocks ended up with sharing buttons and related post links below them, haha. Not what I wanted.

    I eventually worked around the issue by inserting my text blocks with the plain=”true” attribute. In addition, I added a custom function through a code snippet:

    add_filter('text_blocks_shortcode_html', 'jv_fix_reusable_text_blocks', 2, 10);
    
    function jv_fix_reusable_text_blocks( $content ) {
      return do_shortcode($content);
    }

    Maybe that will help you out. Bye!

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.