-1

私のワードプレス投稿の画像リンクをすべてリンクしたい:http://www.simafun.com一部の画像を除く。

だから私はこのコードを見つけて使用します:

<?php
function wpguy_linked_image($content){

    $searchfor = '/(<img[^>]*\/>)/';
    $replacewith = '<a target="_blank" href="'.get_permalink().'">$1</a>';

    {
        $content = preg_replace($searchfor, $replacewith, $content, -1);
    }
    return $content;
}

add_filter('the_content', 'wpguy_linked_image');
?>

すべての写真リンクを置き換えますが、写真の前のリンクは削除しません。

  1. 最初に前のリンクを削除します。たとえば、「http://www.up.simafun.com/2013/01/police-tabriz-1.jpg」にリンクされた私の画像は、私のサイト名(http://www.simafun.com )

  2. ダウンロードにリンクされている画像など、一部の画像をリンクの変更から除外したい (例: "http://up.simafun.com/download-simafun.com.gif")

下手な英語ですみません。

4

1 に答える 1

0

これを使用してください:

$html = preg_replace("/<img.*src="(.*?)".*\/?>/",'<img src="http://up.simafun.com/download-simafun.com.gif">',$html );
于 2013-01-09T13:36:28.607 に答える