First thing is i’m using WordPress > Avada Theme > and Fusion Core Plugin.
What i want to do is strip the content of any post down to a few characters. And what i have works with almost everything minus, post content that uses the Fusion Core plugin.
Here is my function that should get the excerpt and shrink it down.
function get_my_excerpt_by_id($post_id, $length, $strip_html)
{
if(!$length)
$excerpt_length = 35;
else
$excerpt_length = $length;
if(!isset($strip_html) || $strip_html == true)
$strip_html = true;
$the_post = get_post($post_id); //Gets post ID
$the_excerpt = apply_filters('the_content',$the_post->post_content); //Gets post_content to be used as a basis for the excerpt
if($strip_html == true)
$the_excerpt = strip_tags(strip_shortcodes($the_excerpt)); //Strips tags and images
$words = explode(' ', $the_excerpt, $excerpt_length + 1);
if(count($words) > $excerpt_length) :
array_pop($words);
array_push($words, 'â¦');
$the_excerpt = implode(' ', $words);
endif;
return $the_excerpt;
}
So this works like a charm EXCEPT if i’m using Fusion Core Plugin for one of the post types beccause then i get this
‘.fusion-fullwidth-4 { padding-left: 0px !important; ⦒
Any idea why its not stripping the shortcodes and css and html? Although in looking at it, maybe its just the css? that is staying. Thank you!
EDIT::
SO it turns out that its just the css that stays. So now i have to figure out how to remove them. Everything after a period….
I just wanted to post my answer here in case anybody need it for later, Thank you Ghulam Ali, for the help with this answer.
So it turns out that when using Fusion Core, it adds
<style>
tags, that when removed using strip_tags, would leave the css code nested inside of the tag.So, to fix this we first remove all tags, MINUS
<style>
using$the_excerpt = strip_tags(strip_shortcodes($the_excerpt), '<style>');
THEN, we strip out the
<style>
tags and its content using this nifty regex. (that i did not write but don’t know how to give the right credit to the person that did).$the_excerpt = preg_replace("|<styleb[^>]*>(.*?)</style>|s", "", $the_excerpt);
This is the full function i use to get the content and output an excerpt from it. I hope this comes in handy for somebody!
add style tag into strip tags
i hope this will fix.