• Hi everyone,

    I would like to keep HTML markup in Excerpts. I’ve found the code catlists.php which strips any markup but my php isn’t too good and would like to allow <span> and <p> in excerpts. Please advise, code is below from line 228:

    public function get_excerpt($single){
    		if (
    				$this->params['excerpt']=='yes' &&
    				!($this->params['content']=='yes' &&
    				$single->post_content) ){
    			/*
    			 * Strip shortcodes - #5
    			 * https://codex.www.ads-software.com/Function_Reference/strip_shortcodes
    			*/
    			if($single->post_excerpt){
    				return $single->post_excerpt;
    			}
    
    			$lcp_excerpt = strip_shortcodes(strip_tags($single->post_content));
    			$exc_lim = intval($this->params['excerpt_size']);
    			$lcp_excerpt = mb_substr($lcp_excerpt, 0, $exc_lim) . '...';
    			return $lcp_excerpt;
    		} else {
    			return null;
    		}
    	}

    https://www.ads-software.com/extend/plugins/list-category-posts/

Viewing 12 replies - 1 through 12 (of 12 total)
  • Thread Starter jamesthecat7

    (@jamesthecat7)

    Don’t use the code you posted. That’s more than you need to do. Use the link you posted. Paste the code into your functions.php file (the big chunk) and then edit the line 22 that says allowed tags. You have to allow certain tags to show up. This will edit excerpts across the site.

    Thread Starter jamesthecat7

    (@jamesthecat7)

    Hiya, thanks for the response.
    I’m using the mystique theme however functions.php appears to have <p> as an allowed tag already.

    I assumed the plug-in did not share the rules in function.php and used its own rules?

    I’m still not entirely sure what you are trying to accomplish with the site. If you paste the code from your link into the bottom of you functions.php file and edit the lines as per the tutorial, then anywhere (in the theme) that calls for your excerpt will allow the html tags you specified from the original post.
    I don’t think it will work if you use the plugin though, since it appears the plugin is making it’s own excerpt and not using wordpress features to make the excerpt. Where are you trying to get the excerpt to show up?

    Could someone please answer the first question Jamethecat7 asked? The bottom line is MANY of us are using this extremely effective plugin and we need to modify the PLUGIN code, not core WordPress code.

    We need to be able to allow HTML tags so that we can format the inside of the excerpt. For instance, I need the excerpt to style both <p> and <h3>.

    My page of excerpts: https://www.palmyracob.org/honest/about-us/meet-our-staff/.

    If you look at the very bottom excerpt for Missy Thompson, in the first line of the excerpt “Children’s Ministry Mobilize” is styled with an <h3> tag in the original post. But the Plugin strips out the html tags inside the excerpt. There must be a way to get the Plugin to recognize html tags in the excerpt.

    Can someone please answer the original question in this thread – how to modify the Plugin code?

    Untested, but try this.
    Change this line:
    $lcp_excerpt = strip_shortcodes(strip_tags($single->post_content));

    to

    $lcp_excerpt = strip_shortcodes(strip_tags($single->post_content, '<h3><any other tags you want>'));'

    Should work, if not you may need to allow tags in your excerpts too. There’s a bunch of tutorials on that though.

    Mpalmer22,

    Thanks for your suggestion. I haven’t tried it yet. I received another suggestion and have been trying to get it to work.

    Believe me, if I find anything that works, I will make sure to post it on this forum.

    Unfortunately, I couldn’t get Mpalmer22’s suggestion to work. Maybe it’s just the theme I’m using which is “Swift”.

    Sure would be helpful if the Plugin developer would address the problem of having html tags stripped from the Plugin excerpt.

    oliveiravinicius

    (@oliveiravinicius)

    I am also having the same difficulty. I’ve tried everything and could not resolve this issue. If the developer can help would be great. Thank you in advance and excuse my english.

    oliveiravinicius

    (@oliveiravinicius)

    I managed to make the HTML tags appear. Just change the following line to this:

    //$lcp_excerpt = strip_shortcodes(strip_tags($single->post_content));
    $lcp_excerpt = $single->post_content;

    public function get_excerpt($single){
    		if (
    				$this->params['excerpt']=='yes' &&
    				!($this->params['content']=='yes' &&
    				$single->post_content) ){
    			/*
    			 * Strip shortcodes - #5
    			 * https://codex.www.ads-software.com/Function_Reference/strip_shortcodes
    			*/
    			if($single->post_excerpt){
    				return $single->post_excerpt;
    			}
    			$lcp_excerpt = $single->post_content;
    			$exc_lim = intval($this->params['excerpt_size']);
    			$lcp_excerpt = mb_substr($lcp_excerpt, 0, $exc_lim) . '...';
    			return $lcp_excerpt;
    		} else {
    			return null;
    		}
    	}
    oliveiravinicius

    (@oliveiravinicius)

    However now my question is this, would like the excerpt was the entire content that is above the tag <!- more ->, one would have any idea how to do this?

    geologist

    (@geologist)

    Thanks for the suggested code. I’ll give it a try.

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘[Plugin: List category posts] Excerpt – keep formatting by editing catlist.php’ is closed to new replies.