I’m using Divi theme and before it would pull the text directly from the content.. Now it shows the shortcodes.. If I add an excerpt it works, but I want it to pull the first few lines from the content of the post like it was before.
Yes, it appears you’re correct (by chance I happen to have a client with that theme and I tested just now after I saw your comment).
For whatever reason the Divi theme is not honouring the WordPress strip_shortcodes() function. Yet for every other random theme that I have tried, it is working as expected. But Divi just insists on ignoring the function and outputting the shortcode still.
It would be poor form of me to bake in some code specifically just to fix the issue for Divi, and I can’t go back to ‘like it was before’ because that had it’s own set of problems I was made aware of last week (now fixed).
So with that in mind I wouldn’t hold my breathe waiting for me to fix this because I honestly don’t known if and when I’ll get my next chance. As much as this issue is intriguing, I just can’t justify the time spend right now.
I suggest trying an alternative plugin for your Facebook thumbnail requirements. I’m sure there must be some alternatives.
Sorry about that. But good luck!
PS: I will update the FAQ with this as a known issue.
I like your plugin, so I’ve decided to fix it for myself and anyone else having this problem with Divi theme.
So in the first if/else statement under apply_filters(). Add in the regular expression. It removes all content that begins with [et_pb and ends with the closing square bracket.
if($post_page_description) {
$post_page_description = $post_page_description;
} else {
$post = get_post($post->ID);
$content = apply_filters('get_the_content', $post->post_content);
$content = preg_replace('/\[\/?et_pb.*?\]/', '', $content);
$content_chars = substr($content, 0, 300);
$page_description = strip_tags($content_chars);
$post_page_description = str_replace(array("\n", "\t", "\r"), '', $page_description);
}
@marcstampfli
Props on the regular expression work – that’s something I’ve not had any experience with.
Kind of edge case, but what would happen if someone actually had a [ or ] characters in the content that weren’t shortcodes?
-
This reply was modified 6 years, 8 months ago by Michael Ott.
It will only select [et_pb] tags.. if perhaps words are wrapped like this [random words] they will stay as is.
I’ve added an example that shows a word wrapped in square brackets.
So in case someone uses other shortcodes than [et_pb...]
the problem is still there? That would mean your solution with RegEx-replace is case specific and not globally applicable as an update. Or can you also build a RegEx wich can “distinguish” shortcodes from text in brackets?
Regards, david
Ok done.
$content = preg_replace('/\[.*?\]/', '', $content);
Just replace that line of code I added with this.
$content = preg_replace('/\[.*?\]/', '', $content);
I would definitely not recommend that… it will replace all characters within square brackets. Unfortunately the real WP shortcode syntax is much more complex.
https://core.trac.wordpress.org/browser/tags/4.8/src/wp-includes/shortcodes.php#L254
It also doesn’t account for shortcodes that wrap text, in this instance it would remove the shortcodes but leave the innertext, eg.
[bold]test text[/bold]
or [link href="#"]link anchor[/link]
-
This reply was modified 6 years, 8 months ago by aoverton.
-
This reply was modified 6 years, 8 months ago by aoverton.
-
This reply was modified 6 years, 8 months ago by aoverton.
-
This reply was modified 6 years, 8 months ago by aoverton.
So instead of removing them, why not just parse them? That gets you the intended content to be shortened anyway, no?
https://developer.wordpress.org/reference/functions/do_shortcode/
Well, it’s doing what I need it to do on the site i’m working on. The first and 2nd change I posted. I haven’t had any problems, then again I haven’t tested for every possible angle this can break at.
For a perfect global fix I’d need to spend more time on it or if anyone else has time to finish what was started.