Skip to content

Instantly share code, notes, and snippets.

@carasmo
Last active March 24, 2017 21:44
Show Gist options
  • Save carasmo/56904096ae3adb01676a9f2406a2d8b6 to your computer and use it in GitHub Desktop.
Save carasmo/56904096ae3adb01676a9f2406a2d8b6 to your computer and use it in GitHub Desktop.
Allowed Html in Content Limit and Balance tags so that there are not open tags messing up your site.
<?php
//don't add again
/**
*
* Allowed html in get_the_content_limit
*
*/
function yourprefix_allowed_content_limit_tags() {
return '<strong>,<em>,<i>,<ul>,<ol>,<li>,<a>';
}
add_filter( 'get_the_content_limit_allowedtags', 'yourprefix_allowed_content_limit_tags' );
/**
*
* Close open tags in content limit excerpts
* force_balance_tags();
*
*/
function yourprefix_balance_tags_content_limit( $content ) {
$content = force_balance_tags( html_entity_decode( wp_trim_words( htmlentities( $content ) ) ) );
return $content . '<p><a class="more-link" href="' . get_permalink() . '">[Continue Reading]</a></p>';
}
add_filter( 'the_content_limit', 'yourprefix_balance_tags_content_limit' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment