解決WordPress RSS XML第一行錯誤

2009-05-16  
類別: Wordpress, 部落格

自從安裝了Wordpress 2.7.1版之後,許多人向笨笨包反應笨笨包的天空所提供的RSS出現XML錯誤導致無法訂閱。這下就為難笨笨包了,花了幾個晚上都找不到錯誤原因在哪,只好求助網路搜尋。

FEED Validator檢測笨笨包的天空所提供的RSS XML內容,在第一行中總是有一個空白的內容存在,再去看看FEED Validator提供的說明來看:

Message

Blank line before XML declaration (WordPress)

Explanation

If an XML declaration (<?xml ... ?>) appears in your feed, it must be the first thing in the feed, before any whitespace.

Unfortunately, with WordPress it seems all too easy for a plugin, a theme, or for your configuration file to contain a blank line. Further compounding this problem, some – but not all – feed readers compensate for this common error, allowing the error to go undetected for quite a while.

Solution

  • PHP also uses a similar notation: <?php ... ?>. Note that the final php ?> should be omitted from all PHP code files-modules, includes, etc. The closing delimiter is optional in PHP (but not in XML), and removing it helps prevent unwanted white space at the end of files which can cause problems with your feeds.
  • Check your wp-rss2.php and wp-atom.php files for blank lines outside of <? and ?> bracketed sections.
  • Check your wp-config.php file for blank lines outside of <? and ?> bracketed sections.
  • Check your theme’s functions.php file for blank lines outside of <? and ?> bracketed sections.
  • One by one, disable plugins and revalidate until you isolate the one causing the problem.

也就是說在以上所敘述的檔案中將<?php … ?>範圍之外多餘的空白或行數刪除掉即可,看似簡單的動作,結果笨笨包把第一層目錄的PHP檔案全部都檢查修正過了,還是無法解決問題。既然這樣,那笨笨包就繼續檢查第二層目錄,首先就由wp-includes目錄開始著手。這下子笨笨包才發現,在wp-includes目錄內幾乎全部的PHP檔案最後一行都多了一個空行,這下要認真一點將全部多出來的空行刪除掉,然後上傳,沒想到最後終於解決了讓我頭痛了好久的問題。

如果有人出現這個問題的話,別聽信他人說只要將wp-config.php檢查無誤後就行了,認真點,把主目錄以及wp-includes全部檢查修正過,或許會出現意想不到的結果!

[Valid RSS]

為什麼不留下您的觀點?分享創造價值!您說呢?
想要有個性的頭像, 請到gravatar這裡申請!