WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using a plugin called Foliopress WYSIWYG. While using this plugin, images found in the_content loop using relative image path instead of absolute paths. So all the feed images looks broken.

This plugin stores images in http://mysite.com/images folder instead wp-content/uploads folder. So i would like to use filter to replace relative path.

I mean if any img src file looks like /images/2010/03/example.jpg then it should be filtered and replaced with http://mysite.com/images/2010/03/example.jpg

Can anyone give me the snippet? Thanks

share|improve this question
up vote 1 down vote accepted

Something like this should do it, you may have to fiddle with the preg_replace() to get it to work the way you need, but the concept (and, more importantly imo, the regex, is there).

if( is_single() ) {
    add_filter( 'the_content', 'wpse44503_filter_content' );

function wpse44503_filter_content( $content ) {
    $regex = '#src=("|\')'.
    $replace = 'src="'.get_site_url( $2 ).'"';

    $output = preg_replace( $regex, $replace, $content );

    return $output;

That's untested, and I wrote it right into the solution box, so make sure you debug thoroughly and such.

share|improve this answer
Thanks for your answer. However i'm getting this error. syntax error, unexpected T_LNUMBER, expecting T_VARIABLE or '$' Can you fix it? This is the line where i'm getting that error $replace = 'src="'.get_site_url( $2 ).'"'; – Giri Mar 5 '12 at 17:11
try 'src="'.get_site_url().'$2'"'. Like I said, you're gonna have to tinker with it a bit. – mor7ifer Mar 5 '12 at 22:59

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.