Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm having a problem with the_excerpt and can not find the answer anywhere... I simply want to allow links to be clickable when they are displayed via the_excerpt! There has to be a function for this, rather than relying on a plugin. But I can't find it and the advanced excerpt plugins are so complex that I am unable to find the small snippet which makes this work.

share|improve this question

3 Answers 3

up vote 3 down vote accepted

You can use the script I found here: http://aaronrussell.co.uk/legacy/improving-wordpress-the_excerpt/

I've modified it to show links in the excerpt, and removed some of the other functions:

<?php
function keep_my_links($text) {
  global $post;
if ( '' == $text ) {
    $text = get_the_content('');
    $text = apply_filters('the_content', $text);
    $text = str_replace('\]\]\>', ']]&gt;', $text);
    $text = preg_replace('@<script[^>]*?>.*?</script>@si', '', $text);
    $text = strip_tags($text, '<a>');
  }
  return $text;
}
remove_filter('get_the_excerpt', 'wp_trim_excerpt');
add_filter('get_the_excerpt', 'keep_my_links');
?>

The part that fixes it is $text = strip_tags($text, '<a>');. along with remove_filter('get_the_excerpt', 'wp_trim_excerpt');

share|improve this answer

You can use the following plugin for allowing links and other html tags in the excerpts

Plugin: Show links in excerpts wordpress

I have no affiliation regarding the plugin

share|improve this answer
    
Please state you affiliation regarding the plugin –  Pieter Goosen May 26 at 6:38
    
I use advanced excerpts wordpress plugin from the first day I started running my blog: weblogcode. It's very user friendly. It's not been updated but it's compatible with wordpress 3.9. I hope the author of advanced excerpts plugin will update it soon. I am just a basic wordpress user for that plugin. –  user3162185 May 26 at 6:50
    
I have updated your answer to show your affiliation. –  Pieter Goosen May 26 at 6:55
1  
Moreover an answer should be more than just a link to an external site. Please add an explanation: why could that solve the problem? –  Sven May 26 at 7:10

The code basically allows a list of comma separated HTML tags to work in your excerpts which are normally stripped by WordPress. Tested on Genesis and works.

 add_filter( 'get_the_content_limit_allowedtags', 'get_the_content_limit_custom_allowedtags' );

function get_the_content_limit_custom_allowedtags() {
// Add custom tags to this string
return '<script>,<style>,<br>,<em>,<i>,<ul>,<ol>,<li>,<a>'; 
}

Source http://daan.kortenba.ch/add-tags-to-genesis-content-limit-in-content-archives/

share|improve this answer
    
Brad, would you please add a small description to what your code does and how it works. Dumping code is not a constructive answer –  Pieter Goosen May 26 at 6:40
    
Happy to Pieter. The code basically allows a list of comma separated HTML tags to work in your excerpts which are normally stripped by WordPress. Tested on Genesis and works. –  Brad Dalton May 26 at 7:00

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.