-
AuthorPosts
-
September 26, 2019 at 6:23 pm #1142444
So im trying to display a certain amount of blog post content within a search and filter query for my clients site. The issue im running into however is that when I use this line of code:
$content = get_the_content();
$trimmed_content = wp_trim_words( $content, 50, NULL );
echo $trimmed_content;The content that is displayed shows enfolds markup and shortcodes.
When I use the_content instead the page appears shrunken and wonky.
What do I need to add in order for the shortcodes to not appear when printed on the front end?
September 29, 2019 at 7:43 pm #1143119Hey Andrea,
You can remove the shortcodes by using https://codex.wordpress.org/Function_Reference/strip_shortcodes
Best regards,
BasilisSeptember 30, 2019 at 8:40 pm #1143487Hi Basilis,
I have tried the strip_shortcodes hook as well without success.
Here’s what I tried:
$content = get_the_content();
$stripped_content = strip_shortcodes( $content );
echo $stripped_content;When I do this the posts display absolutely nothing. When I try the_content instead the result shows the page looking very unpleasant.
October 2, 2019 at 5:55 am #1144050Hi,
Are you doing this inside a post loop? If not, you may need to add the id of the post inside the get_the_content function. Or try to use the preg_replace function.
$content = get_the_content(); $content = preg_replace('#\[[^\]]+\]#', '',$content); echo $content;Thank you for the update.
Best regards,
IsmaelOctober 7, 2019 at 8:37 pm #1145897Ismael,
This isn’t exactly what I would like to show (because it doesn’t show the styles ALB offers) but we will make this work.
Thanks for letting me know about preg_replace!
October 8, 2019 at 6:31 am #1146017 -
AuthorPosts
- You must be logged in to reply to this topic.
