If you have a look at my home page (http://squittybubbler.com/) and blog (http://squittybubbler.com/blog/) you'll notice that we have hyperlinks in the excerpts. We want to stop this! Is there a simple way to stop this?
Andrzej answers:
Add following lines to your theme's functions.php file:
function my_clean_the_excerpts($excerpt) {
$excerpt = strip_tags( $excerpt, '<p>' );
return $excerpt;
}
add_filter('the_excerpt', 'my_clean_the_excerpts');
Steven Ellis comments:
didn't work.
does it matter where i put it in the functions.php file?
also i noticed on the file there was a line:
// Change Excerpt Length
function tz_excerpt_length($length) {
return 40; }
add_filter('excerpt_length', 'tz_excerpt_length');
// Change Excerpt [...] to new string : WP2.8+
function tz_excerpt_more($excerpt) {
return str_replace('[...]', '...', $excerpt); }
add_filter('wp_trim_excerpt', 'tz_excerpt_more');
Andrzej comments:
Can you try this then:
function my_clean_stripped_content($content) {
if ( is_single() ) {
return $content;
}
else {
$content = strip_tags( $content, '<p>' );
return $content;
}
}
add_filter('the_content', 'my_clean_stripped_content');
Steven Ellis comments:
no that didn't work either.
Andrzej comments:
can you also send index.php file?
Steven Ellis comments:
http://www.mediafire.com/?8smsb2277cwmt37
Andrzej comments:
can you post whole zipped theme folder?
Steven Ellis comments:
here is the theme
http://www.mediafire.com/?wz9h26i9sub27rw
please note i've raised reward to $20.
thanks
Andrzej comments:
yep, I saw.
Andrzej comments:
Please go to your functions.php file, find these line:
function content($num, $more_link_text = '(more...)') {
$theContent = get_the_content($more_link_text);
$output = preg_replace('/<img[^>]+./','', $theContent);
$limit = $num+1;
$content = explode(' ', $output, $limit);
array_pop($content);
$content = implode(" ",$content);
$content = strip_tags($content, '<p><a><address><a><abbr><acronym><b><big><blockquote><br><caption><cite><class><code><col><del><dd><div><dl><dt><em><font><h1><h2><h3><h4><h5><h6><hr><i><img><ins><kbd><li><ol><p><pre><q><s><span><strike><strong><sub><sup><table><tbody><td><tfoot><tr><tt><ul><var>');
echo close_tags($content);
}
These tags which you have there are the "allowed" list. Remove these two [a]s which you have there, so change to:
function content($num, $more_link_text = '(more...)') {
$theContent = get_the_content($more_link_text);
$output = preg_replace('/<img[^>]+./','', $theContent);
$limit = $num+1;
$content = explode(' ', $output, $limit);
array_pop($content);
$content = implode(" ",$content);
$content = strip_tags($content, '<p><address><abbr><acronym><b><big><blockquote><br><caption><cite><class><code><col><del><dd><div><dl><dt><em><font><h1><h2><h3><h4><h5><h6><hr><i><img><ins><kbd><li><ol><p><pre><q><s><span><strike><strong><sub><sup><table><tbody><td><tfoot><tr><tt><ul><var>');
echo close_tags($content);
}
Andrzej comments:
whoa, pasting my code seemed to break the WPQ layout ;) I'll send you via pastebin...
Andrzej comments:
In functions.php find:
http://pastebin.com/pvzGi92j
and change it to:
http://pastebin.com/bnivUwfk
Steven Ellis comments:
brilliant!! thanks for your help.
that worked.
idt answers:
Steven, can you please paste the code for that page? It seems you already have an excerpt filter in place in your functions.php.
Also, please take a look at this plugin: http://wordpress.org/extend/plugins/advanced-excerpt/. I have it in my blog and it seems it does exactly what you wanted to achieve.
Steven Ellis comments:
http://www.mediafire.com/?z9lmz9xepka7ycb
here is the functions.php file.
thanks.
idt comments:
Steven,
In your functions.php, replace this line:
$content = strip_tags($content, '<p><a><address><a><abbr><acronym><b><big><blockquote><br><caption><cite><class><code><col><del><dd><div><dl><dt><em><font><h1><h2><h3><h4><h5><h6><hr><i><img><ins><kbd><li><ol><p><pre><q><s><span><strike><strong><sub><sup><table><tbody><td><tfoot><tr><tt><ul><var>');
with this:
$content = strip_tags($content, '<p><address><abbr><acronym><b><big><blockquote><br><caption><cite><class><code><col><del><dd><div><dl><dt><em><font><h1><h2><h3><h4><h5><h6><hr><i><img><ins><kbd><li><ol><p><pre><q><s><span><strike><strong><sub><sup><table><tbody><td><tfoot><tr><tt><ul><var>');
idt comments:
What happened with the layout?
Oopps... Andrzej already pointed it above. I should have refreshed the page.