Frage

i want to remove in wordpress the image size from the url of an image who is grabbed via RSS from an external site. this images are generated random based the rss so the string must be replaced or removed auto.

the URL looks like this:

wp-content/uploads/2014/04/10154286_630741873674479_8554167680140056790_n-160x132.jpg from the _n-160x132.jpg must be removed the -160x132 to get the full size of the image.

I have try with this but it does not works:

<?php 
 function remove_url_size( $content ) { 
    $content =
        preg_replace('_n[^>]*.jpg', '_n.jpg', $content);
    return $content;
} 
add_filter( 'the_content', 'remove_url_size' ); 
?>

I repeat, it will not be for only one image but unknown random images with the same method.

War es hilfreich?

Lösung

You were almost there. The only problem in your code is that you do not pass a valid regular expression pattern, it should be surrounded by /s

<?php 
 function remove_url_size( $content ) { 
    $content =
        preg_replace('/_n[^>]*.jpg/', '_n.jpg', $content);
    return $content;
} 
add_filter( 'the_content', 'remove_url_size' ); 
?>

Andere Tipps

Try this:

$img_link = "wp-content/uploads/2014/04/10154286_630741873674479_8554167680140056790_n-160x132.jpg";
$new_img_link = preg_replace("/\_n[^\.]*\.jpg/", "_n.jpg", $img_link);
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top