I have a category page that I need to show some of the content of a the posts with HTML tags such as images.
Site - http://hoffwebsites.com/wp-hoff-testing/ms-conversations/
I have found this code that does the trick.
I have this in my functions.php
function technig_content($limit){
$content = explode(' ', get_the_content(), $limit);
if (count($content)>=$limit){
array_pop($content);
$content = implode(" ",$content).'...';
} else {
$content = implode(" ",$content);
}
$content = preg_replace('/\[.+\]/','', $content);
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
return $content;
}
And this where I want to the code to go.
<?php echo technig_content(170); ?>
However, it is leaving open HTML tags sometimes that throws off the page structure in some case. Usually an open bold or italic or bulleted list.
I know there is Balance Tags - https://codex.wordpress.org/Function_Reference/balanceTags
But I do not know how to incorporate that with my code.
I have tried with no luck, any thoughts?
<?php echo technig_content(170); echo balanceTags($technig_content, true); ?>