views:

27

answers:

1

According to the WordPress wiki pages on developing themes, I have to call wp_head() in the <head> tag so that WordPress can insert some additional HTML code into my theme. Normally this doesn't cause any validation problems, but when I search for something on my custom-themed WordPress blog one of the automatically inserted lines doesn't pass XHTML 1.0 Strict validation.

This is the offending line:

<link rel="alternate" type="application/rss+xml" title="My Blog &raquo; search results for &#8220;hello world&#8221;" href="http://&lt;!-- Path to my blog -->/?s=hello%20world&feed=rss2" />

That ampersand before feed=rss2 causes trouble. Replacing it with &amp; should fix this, but since WordPress automatically inserts the code there's no way to do that. Or is there?

No plugins are running on my site, by the way.

+2  A: 

There is indeed a way to do it using a filter in your theme. If you don't already have one, create a functions.php in your theme directory. Then paste this code in:

<?php

    function encode_search_feed($link){
        return htmlentities($link); 
    } 
    add_filter('search_feed_link', 'encode_search_feed');

?>

If you already have a functions.php, you can just paste the function and add_filter call anywhere in the file.

Pat
Thanks, that totally worked!
Pieter
Glad to hear - you can use filters to alter pretty much all default WordPress function output.
Pat
Nice and simple!
hsatterwhite
Faster: `add_filter('search_feed_link', 'htmlspecialchars');`
toscho
@toscho: thanks for the tip.
Pat