Support » Fixing WordPress » Remove image captions / shortcode from main news page

  • Hello – I have a custom wordpress website and our news page contains a list of all our ‘posts’ by way of teaser text (approx the first 20 words).

    Some of these posts contain images with captions – however the caption code appears in the teaser text on the main news page!

    I have spent several hours trying to find a way to remove these – but none seem to work.

    The closest I got was

    add_filter('the_content', 'strip_shortcodes');
    function remove_shortcode_from_index($content) {
      if ( is_search() ) {
        $content = strip_shortcodes( $content );
      return $content;

    But this only works on the posts, not on the main news index. And even then it removes the entire image rather than just the caption.

Viewing 4 replies - 1 through 4 (of 4 total)
  • esmi


    Forum Moderator

    Use the_excerpt() on the page – not the_content().

    We don’t want to have to manually write excerpts each time if possible – there are thousands of posts and this adds an extra time consuming step



    Forum Moderator

    You don’t have to. the_excerpt creates an automatic excerpt. If you want to reduce the default excerpt output from 55 words to 20, use something like:

    // Decrease excerpt length
    function my_excerpt_length($length) {
    	return 20; // Or whatever you want the length to be.
    add_filter('excerpt_length', 'my_excerpt_length');

    Another new handy function which might help in similar situation wp_trim_words()

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Remove image captions / shortcode from main news page’ is closed to new replies.