1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Links in Wordpress Excerpts?

Discussion in 'WordPress' started by samie, Dec 28, 2013.

  1. #1
    I noticed that with Wordpress that they actually don't allow links in their excerpts. I didn't understand why until I actually proceeded to re-write some of the functions. However, now I know why they are not used. It seems that if your excerpt gets cutoff while in an anchor tag that it actually breaks the link and the rest of your page ends up being a link because the anchor tag didn't get closed properly.

    Has anyone else experienced this and/or know how I could get this fixed?
     
    samie, Dec 28, 2013 IP
  2. themes4all

    themes4all Well-Known Member

    Messages:
    662
    Likes Received:
    47
    Best Answers:
    6
    Trophy Points:
    100
    #2
    hello,

    the wordpress avoid using html in Excerpts to avoid the CSS problems.. but you can use a simple function :

    
    function new_trim_excerpt($text) {
    global $post;
    if ( '' == $text ) {
    $text = get_the_content('');
    $text = apply_filters('the_content', $text);
    $text = str_replace('\]\]\>', ']]>', $text);
    $text = preg_replace('@<script[^>]*?>.*?</script>@si', '', $text);
    $text = strip_tags($text, '<a>');
    $excerpt_length = 80;
    $words = explode(' ', $text, $excerpt_length + 1);
    if (count($words)> $excerpt_length) {
    array_pop($words);
    array_push($words, '</a><a>ID) . '">Read the Rest...</a>');
    $text = implode(' ', $words);
    }
    }
    return $text;
    }
    remove_filter('get_the_excerpt', 'wp_trim_excerpt');
    add_filter('get_the_excerpt', 'new_trim_excerpt');
    
    Code (markup):
    You can change the $excerpt_length = 80 to more than that... all depend about your needs... Normally All new themes allow the add of Links on the Excerpt but maybe this function can help the ones they got the same problem like yours!
     
    themes4all, Dec 30, 2013 IP
    samie likes this.