开发者

Code supplied by WordPress breaks my XHTML 1.0 Strict-compliant theme

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://<!--开发者_JS百科 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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜