Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #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?

    #1143119

    Hey Andrea,

    You can remove the shortcodes by using https://codex.wordpress.org/Function_Reference/strip_shortcodes

    Best regards,
    Basilis

    #1143487

    Hi 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.

    #1144050

    Hi,

    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,
    Ismael

    #1145897

    Ismael,

    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!

    #1146017

    Hi,

    Thanks for the update, please let us know if you should need any further help on the topic.

    Best regards,
    Rikard

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.