Enable Formatting Tags for Content Limit in Genesis Featured Posts widget

gallerygenesis

Genesis Framework has same function that return the content after trimming and it strips all HTML
The following code help you keep or filter some HTML tags when you are using Content Limit in Theme Settings or Widgets (e.g Genesis – Featured Posts widget)

Add following to functions.php in the Genesis Framework child theme


add_filter('get_the_content_limit_allowedtags', 'childtheme_custom_allowedtags');
function childtheme_custom_allowedtags() {
return '<script>,<style>,<b>,<br>,<em>'; //add whatever tags you want to this string
}

The code been tested on Gallery Child Theme for Genesis Framework

Keep HTML Tags in WordPress Limit Posts – the_content_limit

WordPress - the logoThis function, the_content_limit  controls the maximum amount of characters displayed for an entry on the main page on WordPress homepage posts, e.g Featured Posts, Recent Posts
However , the_content_limit stripped HTML tags just like the_excerpt. What if we want to keep HTML tags

We make modification to the function, the_content_limit which is usually found in functions.php


function the_content_limit($max_char, $more_link_text = '(more...)', $stripteaser = 0, $more_file = '') {
$content = get_the_content($more_link_text, $stripteaser, $more_file);
// remove  shortcode
$content = preg_replace("/\/", '', $content);
// short codes are applied

$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
$content = strip_tags($content,'
,<b>,<strong>,<a>,<i>,
');

if ((strlen($content)>$max_char) && ($espacio = strpos($content, " ", $max_char ))) {
$content = substr($content, 0, $espacio);
$content = $content;
echo "
";
echo $content;
echo "...";
echo "

";
}
else {
echo "
";
echo $content;
echo "

";
}
}

We remove $content = strip_tags($content);  from original code of the_content_limit and replace it with $content = strip_tags($content,'<p>,<b>,<strong>,<a>,<i>,<br>’);
This will allow the_content_limit to show paragraph, bold texts, italic texts.

What is strip_tags?

We can remove all html tags from the content by using strip_tags string function in PHP. This function can be used to collect only the content part without reading the html formatting of the page. Here is the syntax

strip_tags (input string [, string allowable_tags])

This function also allows one optional string where we can keep the tags which are not to be removed. Say we don’t want the hyper links to be removed. So we will allow the linking tag <a href to be kept as it is. Here is the syntax for this.

strip_tags($string_str, ‘<a>’);

In the above code $string_str is the input string, in our case it is $content

Change Default WordPress Logo Link from wordpress.org to Your Domain Name

WordPress - the logoWhen you open WordPress login page, the default logo links to WordPress.org. This is a quick tip for using your own link. Open the functions.php file. Then, add the following lines of code. And be sure to remember the PHP tag enclosure.

function wp_url_loginlogo(){
	return "http://yourdomain.com/"; // your URL here
}
add_filter('login_headerurl', 'wpc_url_loginlogo');

WordPress Limit Post

This function controls the maximum amount of characters displayed for an entry on the main page. If the set limit is surpassed, the text on the entry will be chopped to that amount of characters, otherwise the content will be showed unchanged.

Add following code to functions.php in your theme folder


function the_content_limit($max_char, $more_link_text = '(more...)', $stripteaser = 0, $more_file = '') {
$content = get_the_content($more_link_text, $stripteaser, $more_file);
// remove  shortcode
$content = preg_replace(&quot;/\/&quot;, '', $content);
// short codes are applied

$content = apply_filters('the_content', $content);
$content = str_replace(']]&gt;', ']]&amp;gt;', $content);
$content = strip_tags($content);

if ((strlen($content)&gt;$max_char) &amp;&amp; ($espacio = strpos($content, &quot; &quot;, $max_char ))) {
$content = substr($content, 0, $espacio);
$content = $content;
echo &quot;&lt;p&gt;&quot;;
echo $content;
echo &quot;...&quot;;
echo &quot;&lt;/p&gt;&quot;;
}
else {
echo &quot;&lt;p&gt;&quot;;
echo $content;
echo &quot;&lt;/p&gt;&quot;;
}
}

usage :
add this code

 the_content_limit('100');  

inside WordPress loop. This function usually replace

 the_content(); 

credits: this function from Limit Posts plugin  (the original plugin author site seems down at the moment). I have updated code above  to remove Image Caption for showing