0

Hi i created code to show excerpt in my wordpress theme but when in put the urls within my post show them in my excerpt this is my code

<div class="standard-excerpt">
    <?php
        $content = get_the_content();
        $trimmed_content = wp_trim_words( $content, 200 );
        echo $trimmed_content;
    ?>
        <a class="text-info" href="<?php the_permalink(); ?>">
            <?php _e('[Continue Reading]', 'Yallanpe Theme'); ?>
        </a>
</div>

how i can restrict the URL or Links Until don't show them in my excerpt? does i can do this by preg_match_all ? or no? if i can how can i do this? please i want modify the $trimmed_content Until don't show me the Url and Links in my excerpt.

Shwan Namiq
  • 631
  • 8
  • 21

1 Answers1

0

I think you're looking for the PHP function strip_tags. Try this:

<div class="standard-excerpt">
    <?php
        $content = strip_tags( get_the_content() );
        $trimmed_content = wp_trim_words( $content , 200 );
        echo $trimmed_content;
    ?>
        <a class="text-info" href="<?php the_permalink(); ?>">
            <?php _e('[Continue Reading]', 'Yallanpe Theme'); ?>
        </a>
</div>

NOTE: this wont remove the words between the <a> tags, just stop them being clickable

haxxxton
  • 6,422
  • 3
  • 27
  • 57
  • not work with me the output only is array(); and don't show any other excerpt words – Shwan Namiq Jul 14 '14 at 05:17
  • @ShwanNamiq try with updated code.. (moved the tag stripping to around the `get_the_content()` call) – haxxxton Jul 14 '14 at 05:34
  • if you can please modify my code bu using preg_matche_all for restrict the lnks and urls to show with my excerpt code i don't want use srtip_tags function because also show links and urls – Shwan Namiq Jul 14 '14 at 06:01
  • i mention that this would be the case in the 'NOTE' of my answer. depending how you write your content, removing the links entirely could read weirdly. as per this very famous answer about html and regex http://stackoverflow.com/a/1732454/648350 .. it shouldnt be done – haxxxton Jul 14 '14 at 06:23