• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

Putting tags back in excerpts, works in one of three "identical" sites

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › Design Tips and Tricks › Putting tags back in excerpts, works in one of three "identical" sites

This topic is: not resolved

Tagged: Excerpt, html tags, paragraphs

  • This topic has 2 replies, 2 voices, and was last updated 8 years, 2 months ago by David Borrink.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • March 27, 2017 at 6:53 am #203850
    David Borrink
    Participant

    I have a function to put tags back into the excepts on my front page. I’ve put this in three sites that are using the same basic theme, based on Genesis Sample.

    Here is the function. You’ll see the paragraph and link tags specified in the eighth line.

    function my_custom_excerpt($text) {
    	global $post;
    	if ( '' == $text ) {
    		$text = get_the_content('');
    		$text = apply_filters('the_content', $text);
    		$text = str_replace('\]\]\>', ']]>', $text);
    		$fulltext = str_replace('\]\]\>', ']]>', $text);
    		$text = strip_tags($text, '<em><p><a>');
    		$excerpt_length = 100;
    		$words = explode(' ', $text, $excerpt_length + 1);
    		if (count($words) > $excerpt_length) {
    			array_pop($words);
    			array_push($words, '... <a href="'. esc_url( get_permalink() ) . '">Read more ยป</a>');
    			$text = implode(' ', $words);
    		}
    		else {
    			$text = $fulltext;
    		}
    	}
    	return $text;
    }
    remove_filter('get_the_excerpt', 'wp_trim_excerpt');
    add_filter('get_the_excerpt', 'my_custom_excerpt');

    Site #1 was developed first. The code is not working on the excerpts.

    Site #2 and #3 were made from tweaks of Site #1. It’s the same basic design, as you’ll notice if you take the links.

    Site #2 also has the code not working.

    Site #3 is the site where the function is working correctly. This baffles me. I’ve looked into plug-ins as a possible culprit, #1 has a lot, #2 has many, and #3 not so much. I tried turning #2’s plugins off one by one to see if that would be the reason to allow the function to work. But no success.

    I look at the HTML and #3’s content clearly has <p> and <br> tags in it. Does anyone have any insight what I could do to determine why #3 is working, so that I can fix #1 and #2?

    Thanks.

    http://aquietsimplelife.com
    March 27, 2017 at 7:10 am #203890
    Victor Font
    Moderator

    Are all three sites displaying excerpts and not content limited text? There's a different filter for content limited text.

    There's also a much simpler way to add tags back in. You've written a lot of code, when you only need a couple of lines: https://wpsites.net/wordpress-tips/add-back-html-tags-stripped-from-content-limit-excerpts-in-wordpress/


    Regards,

    Victor
    https://victorfont.com/
    Call us toll free: 844-VIC-FONT (842-3668)
    Have you requested your free website audit yet?

    March 27, 2017 at 12:04 pm #203901
    David Borrink
    Participant

    Yes, I'm doing content limited excerpts for this. I had used that code you suggested, and over the weekend I worked with someone to solve the closed tags issue. So that post you linked to now has an update. I have returned to that code again.

    I have put it on all three sites, but site #3 is now going down, being merged into #2. So we're now dealing with #1 and #2 only.

    The code shows the italics and the links like I want, but the paragraph and break tags are not working. Brad's code doesn't have <p> tags, so I added them.

    I also added a function via another user to put the "read more" back into the situation.

    There's a new consequence. The number of characters setting in the Genesis Settings panel is not having an effect.

    Here is the complete set of code I added....

    add_filter( 'get_the_content_limit_allowedtags', 'get_the_content_limit_custom_allowedtags' );
    /**
    * @author Brad Dalton
    * @example http://wp.me/p1lTu0-a5w
    */
    function get_the_content_limit_custom_allowedtags() {
    	// Add custom tags to this string
    	return '<script>,<style>,<br>,<em>,<i>,<ul>,<ol>,<li>,<a>,<p>'; 
    }
    
    add_filter( 'the_content_limit', 'force_balance_tags_content_limit' );
    function force_balance_tags_content_limit( $content ) {
    $content = force_balance_tags( html_entity_decode( wp_trim_words( htmlentities( $content ) ) ) );
    return $content;
    }
    
    function yourprefix_read_more_for_content_limit( $content ) {
    	return $content . '<p><a class="more-link" href="' . get_permalink() . '">[Continue Reading]</a></p>';
    }
    add_filter( 'the_content_limit', 'yourprefix_read_more_for_content_limit' );
  • Author
    Posts
Viewing 3 posts - 1 through 3 (of 3 total)
  • The forum ‘Design Tips and Tricks’ is closed to new topics and replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2025 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble