• 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

Trying to restore tags to the excerpt, needing paragraphs to display correctly

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 › Trying to restore tags to the excerpt, needing paragraphs to display correctly

This topic is: not resolved

Tagged: brad dalton, Excerpt, paragraph, replace, tags

  • This topic has 3 replies, 2 voices, and was last updated 8 years, 3 months ago by David Borrink.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • February 17, 2017 at 12:36 pm #201399
    David Borrink
    Participant

    I tried Brad Dalton's code below to restore the stripped tags in front page excerpts. It restores tags, but if my excerpt has a tag that doesn't get closed before the excerpt cutoff point, then all the rest of my content on the page carries the tag. So if italics are in an excerpt but don't get closed off, then from that point on all the content in my page becomes italic.

    // Add html to archive content limit.
    add_filter( 'get_the_content_limit_allowedtags', 'custom_get_the_content_limit_allowedtags' );
    function custom_get_the_content_limit_allowedtags() {
    
    	return '<script>,<style>,<strong>,<b>,<br>,<em>,<i>,<ul>,<ol>,<li>,<a>';
    }

    I tried adding <p> to the list of tags above to return, but that doesn't do anything because the "text" mode in the visual editor doesn't have <p> tags. Is there any way to get paragraphs to be separated?

    We recently moved our site from a TwentyTwelve child theme to Genesis, and we had paragraph breaks show up in that theme in the excerpts using the following code. It doesn't work when we try it in Genesis. I don't understand most of this code so I'm not sure if it somehow can look at the text and determine if paragraph breaks are needed.

    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, '<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');
    http://sallieborrink.com
    February 17, 2017 at 1:15 pm #201404
    Victor Font
    Moderator

    The function you are using to try to add paragraph tags is actually stripping tags. That's what this line of code does: $text = strip_tags($text, '<p>);

    As for the text editor, you can just add paragraph tags manually.


    Regards,

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

    February 17, 2017 at 1:35 pm #201406
    David Borrink
    Participant

    I can see that it does strip the tags (the one I was trying).

    I understand that I can add the paragraph tags manually, of course, but when I view my posts on a single post, there are separated paragraphs. How does the single post create those visual breaks when there are no <p> tags in the actual post in the text editor?

    Also, why does Brad's code not allow for the tags to close automatically at the end of the excerpt, and prevent the same tag from continuing down the page?

    February 18, 2017 at 4:47 pm #201474
    David Borrink
    Participant

    I've done some reading on how function wpautop is supposed to add <p> tags around paragraphs that have double line breaks. That explains why there are no <p> tags in the text editor. So it puts those tags in for single posts.

    I'd like to get the <p> tags to work in excerpts, but I'm not seeing a way to figure that out. I've read through the formatting.php file and found the wpautop section, but it's extremely cryptic for me with all it's characters that obviously mean certain types of content setups. Too many slashes and brackets to understand.

    The WordPress reference at https://codex.wordpress.org/Function_Reference/wpautop says that wpautop filters the_excerpt. Okay, but shouldn't that mean that it makes the excerpt contain <p> tags? It's not doing that. Is this a flaw with the Genesis Sample theme? I'm not sure what to do here.

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