ひとり勉強ログ

ITエンジニアの勉強したことメモ

WordPressの「続きを読む」のリンク先から「#(シャープ)を消す方法」

WordPressでは、投稿で「<!--more-->」などを記述して、「続きを読む」の機能を使用することがあると思います。

この<!--more-->で表示される「続きを読む」などのリンク先(アンカータグ)には最後に「#more-xxx」という内部リンクが入ってしまいます。

今回はリンク先からこの「#more-xxx」を除く方法を紹介します。

■記述ファイル functions.php

ソースコード [php] // #moreリンクの#を無効化 function custom_content_more_link( $output ) { $output = preg_replace('/#more-[\d]+/i', '', $output ); return $output; } add_filter( 'the_content_more_link', 'custom_content_more_link' ); [/php]

※参照サイト WordPressを使ったWebサイトでfunctions.phpによく書いてるやつ