WordPress.org

Ready to get started?Download WordPress

Forums

How to limit post content and remove image caption from it (1 post)

  1. voiceofbsl
    Member
    Posted 1 year ago #

    Hello,

    I am using this function to limit the content in my themes. But the problem is whenever I call the function, it also displays the image caption. I want to remove the image caption when calling the_content_limit function.

    Here is the code:

    function the_content_limit($max_char, $more_link_text = '', $stripteaser = 0, $more_file = '') {
    
        $content = get_the_content($more_link_text, $stripteaser, $more_file);
    
        $content = apply_filters('the_content', $content);
    
        $content = str_replace(']]>', ']]>', $content);
    
        $content = strip_tags($content);
    
       if (strlen($_GET['p']) > 0) {
    
          echo "";
    
          echo $content;
    
          echo "&nbsp;<a href='";
    
          the_permalink();
    
          echo "'>"."Read More &rarr;</a>";
    
          echo "";
    
       }
    
       else if ((strlen($content)>$max_char) && ($espacio = strpos($content, " ", $max_char ))) {
    
            $content = substr($content, 0, $espacio);
    
            $content = $content;
    
            echo "";
    
            echo $content;
    
            echo "...";
    
            echo "&nbsp;<a href='";
    
            the_permalink();
    
            echo "'>"."</a>";
    
            echo "";
    
       }
    
       else {
    
          echo "";
    
          echo $content;
    
          echo "&nbsp;<a href='";
    
          the_permalink();
    
          echo "'>"."Read More &rarr;</a>";
    
          echo "";
    
       }
    
    }

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags