Posted Post

Posted People, Posted Life.

Fix Weird WordPress Relative Path Problem

After update WordPress to 3.0, I noticed some weird server-relative path appear in the post source file, for example:

<a href=”./tag/something/”>something</a>

And it should be ( and always before update), a absolute path like

<a href=”http://postedpost.com/tag/something/”>something</a>

It’s strange and hard to notice because the relative path works fine in the blog site itself, but, but it will mess up the code at third party, like feedburner code etc.

After investigate, I convinced the problem is the html code editor does not load properly.

The html editor located at /wp-includes/js/tinymce/, you can check this folder, lots and lots of file inside. I can understand why it’s not load right every time.

Anyway, a little code can fix this problem, dynamic replace the relative path to absolute path when code displayed, because simply relative path does not make sense.

function postedpost_content($content){
 $siteurl = get_settings('siteurl');
 if (strpos($content, '"../') !== false) $content = str_replace('"../', '"' . $siteurl . '/', $content);
 return $content;
}
add_filter('the_content', 'postedpost_content', 20, 1);

Put the code into postedpost.php file at mu-plugins folder, done.

No comments yet »

Your comment

HTML-Tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>