サポート » 使い方全般 » 検索結果内の特定のURLを書き換える

  • 解決済 ForestRiver

    (@forestriver)


    サイト検索で検索した結果の特定のURLを書き換えたいのですが、
    このようなことは可能なのでしょうか?

    投稿内容のソートしかやり方がわからないので

    知っている方がおられたら
    よろしくお願いいたします。

4件の返信を表示中 - 1 - 4件目 (全4件中)
  • http://wpdocs.osdn.jp/%E6%A4%9C%E7%B4%A2%E3%83%9A%E3%83%BC%E3%82%B8%E3%81%AE%E4%BD%9C%E6%88%90

    を参考に、テーマに検索結果テンプレートを作成(あるいは存在するテーマもある)し、その中で表示しているコード部分で文字列置換すればいいのではないかなと思います。
    Twenty Sixteen テーマならば、search.php が検索結果テンプレートであり、
    たとえば検索結果のコンテンツに関しての置換なら

    function the_content_replace($content){
    	$content = str_replace("http://localhost","http://hogege", $content);
    	return $content;
    }
    add_filter('the_content', 'the_content_replace');
    
    while ( have_posts() ) : the_post();
    

    なんかでリンク変更できたりするんじゃないかなーと思います。

    トピック投稿者 ForestRiver

    (@forestriver)

    kimipooh様 ご返答ありがとうございます。
    なるほど、seaarch.phpの the_contentを編集すればよいのですね。

    なにか難しく考えていました。
    上記のサイトも参考に書き換えを行おうと思います。

    有難う御座います。

    トピック投稿者 ForestRiver

    (@forestriver)

    Avadaというテーマを利用していたのですが
    wp-content/themes/Avada/templatesのblog-layout.php内の
    157行目あたりの

    // Render the post title
        //From here
            $this_search_title=avada_render_post_title( get_the_ID() );
            $beforeurl='正規表現';
            $afterurl='置き換える文字列';
            $this_search_title = preg_replace($beforeurl,$afterurl, $this_search_title);
            echo $this_search_title;
            //To here
    
        // Render post meta for grid and timeline layouts
        if ( $blog_layout == 'grid' ||
             $blog_layout == 'timeline'

    というように書き換えることで無事完了しました。
    有難う御座います。

    トピック投稿者 ForestRiver

    (@forestriver)

    解決しました

4件の返信を表示中 - 1 - 4件目 (全4件中)
  • トピック「検索結果内の特定のURLを書き換える」には新たに返信することはできません。