• Resolved brodiebrodie

    (@brodiebrodie)


    Hi I have tried using the code

    `add_filter(‘uagb_single_post_excerpt_masonry’, function($excerpt, $id, $attr) {
    return get_the_content();
    },10, 3 );

    And now the html formatting in the grid is maintained, but I get the entire post, instead of the excerpt. How can I display just the required word count, and keep the html formatting?

    Many Thanks

    • This topic was modified 3 years, 8 months ago by brodiebrodie.
    • This topic was modified 3 years, 8 months ago by brodiebrodie.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support Team Brainstorm Force

    (@brainstormteam)

    Hello @brodiebrodie ,

    You can limit the get_the_content by using the below custom code. Please check –

    add_filter('uagb_single_post_excerpt_masonry', function($excerpt, $id, $attr) {
      return custom_post_content(5);
    },10, 3 );
    function custom_post_content($limit) {
    	global $post;
    	$permalink = get_permalink($post->ID);
    	$readmore = "<a href='$permalink'> View article ... </a>";
       $content = explode(' ', get_the_content(), $limit);
       if (count($content)>=$limit) {
    	 array_pop($content);
    	 $content = implode(" ",$content).$readmore;
       } else {
    	 $content = implode(" ",$content);
       }	
       $content = preg_replace('/\[.+\]/','', $content);
       $content = apply_filters('the_content', $content); 
       $content = str_replace(']]>', ']]>', $content);
       return $content;
     }

    Refer to this link for more information.

    I hope this helps.

    Regards,
    Sweta

    Thread Starter brodiebrodie

    (@brodiebrodie)

    Thank you for your help, that works well now!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Keep html formatting in post masonry grid excerpt’ is closed to new replies.