wordpress permalinks and local images

[posted: ]  [0 comments]

it took me until now to start using permalinks. the main reason: in all my previous posts, i had included images manually with the relative URI — e.g. <img src="2007/12/01/test.jpg”>.
the permalink for this post is a virtual folder
and so the above image is looked for under
it’s not there of course, so it won’t be displayed correctly.
the problem is similar for internal links such as <a href="gallery.php”>.

instead of correcting every single post manually, i just added the following lines to wordpress/wp-includes/formatting.php, line 28:

$curl = str_replace('src="', 'src="/', $curl);
$curl = str_replace('src="/http://', 'src="http://', $curl);
$curl = str_replace('href="', 'href="/', $curl);
$curl = str_replace('href="/http://', 'href="http://', $curl);

lines 1 and 3 add the necessary root-slash to every src and href, lines 2 and 4 remove them for all external links.

if your all of your images and/or internal pages are in a subfolder, change the first and third line accordingly:

$curl = str_replace('src="', 'src="/subfolder/', $curl);


[category: computers & technology] [tags: ]

Leave a Reply