• 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

Code added to restore excerpt tags controls my excerpt length

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 › Code added to restore excerpt tags controls my excerpt length

This topic is: not resolved

Tagged: get_the_content_limit

  • This topic has 8 replies, 2 voices, and was last updated 8 years ago by Brad Dalton.
Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • April 20, 2018 at 7:08 pm #219160
    David Borrink
    Participant

    I found this code to allow tags on the excerpts on the front page. It brings back all the tags I want in my content, but with two critical problems explained below after the code.

    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>,<strong>'; 
    }
    
    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' );

    1) No matter what I set my character limit to on the Archive Settings on the Genesis Settings page, it remains unchanged. My character count looks to be about 250-300 when I use the code below. If I remove this code it becomes whatever I choose in the Genesis settings.

    2) I cannot get the paragraphs to break into separate paragraphs like a single post. I have the <p> tag specified, but it's not taking. I want to be able to show the flow of my posts with separate paragraph as they are in the single posts, and not have them all run together. How can I get that? What is stripped out on the front page so that I know what I could put back in to get what I want?

    I currently do not have this code running on my site.

    http://aquietsimplelife.com
    April 29, 2018 at 3:49 am #219390
    Brad Dalton
    Participant

    Hello David

    What you can do if you want to display content with HTML tags in excerpts is add the HTML to the Excerpt meta box. Based on my testing this works however it only works when using the Genesis > Content Archives > Display > Entry Excerpts. It won't work if using the Entry Content option.

    Anything else and you might need custom code written to do exactly what you want.


    Tutorials for StudioPress Themes.

    April 29, 2018 at 5:27 am #219395
    Brad Dalton
    Participant

    If you prefer to allow HTML tags in the excerpt without having to use manual excerpts, based on my testing, this solution works https://wordpress.stackexchange.com/a/141136

    Again, this only works when using the Genesis > Content Archives > Display > Entry Excerpts option.


    Tutorials for StudioPress Themes.

    April 29, 2018 at 5:31 am #219396
    Brad Dalton
    Participant

    If you are using the Genesis > Content Archives > Display > Entry Content option, this code enables the use of HTML tags in the content limit on archives.


    Tutorials for StudioPress Themes.

    April 29, 2018 at 5:39 am #219397
    Brad Dalton
    Participant

    You can then use this code to modify the read more link however this code only works when using the Genesis > Content Archives > Display > Entry Content option.


    Tutorials for StudioPress Themes.

    April 29, 2018 at 5:44 am #219398
    Brad Dalton
    Participant

    Based on my testing, the 2nd and 3rd code snippets you posted do nothing when using Genesis > Content Archives > Display > Entry Content option. Only the 1st snippet ( which came from my site ) works when using this option.

    Not sure where you got snippets 2 & 3 however i wouldn't suggest using them with Genesis. as there's genesis specific functions you can use to limit the content when using the Genesis > Content Archives > Display > Entry Content option.


    Tutorials for StudioPress Themes.

    April 29, 2018 at 5:56 am #219399
    Brad Dalton
    Participant

    When using the Genesis > Content Archives > Display > Entry Excerpts option you can modify the following value in this code snippet to control the excerpt length

    $excerpt_word_count = 75;


    Tutorials for StudioPress Themes.

    April 30, 2018 at 4:29 pm #219447
    David Borrink
    Participant

    Hi Brad, thanks for all your information. I put only this code in and tried it,

    add_filter( 'get_the_content_limit_allowedtags', 'get_the_content_limit_custom_allowedtags' );
    
    function get_the_content_limit_custom_allowedtags() {
    	// Add custom tags to this string
    	return '<script>,<style>,<br>,<em>,<i>,<ul>,<ol>,<li>,<a>,<p>,<strong>'; 
    }

    and set the Genesis > Content Archives > Display > Entry Content option to Entry Content with a 1000 for the moment. There are shorter-than-1000 posts on the front page, but the longer ones appear to have the length okay. I haven't tried the other code yet regarding excerpt length.

    I see a lot of my tags are showing up now, bolds, italics, links, and it looks like they're closing properly at the moment. What I don't understand is why <p> doesn't work, even though it's specced in the code. That's the one I want to really fix so the shortened "excerpt" starts to read like the actual post.

    May 4, 2018 at 5:46 am #219538
    Brad Dalton
    Participant

    Another option is to use the get_the_content_limit filter located on line 85 of formatting.php

    	
    return apply_filters( 'get_the_content_limit', $output, $content, $link, $max_characters );
    

    You can use this filter to change the value for the $content variable so the content limit includes p tags.

    One way to do this would be to use the_content rather than get_the_content however there is probably other methods you can use.

    Based on my testing this enables p tags when using the content limit.


    Tutorials for StudioPress Themes.

  • Author
    Posts
Viewing 9 posts - 1 through 9 (of 9 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

© 2026 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