スポンサーリンク

続きを読むをクリックした場合に表示される「#more」を削除する方法

CMS「WordPress」で「続きを読む」をクリックして記事を表示した場合にURL末尾に付く「#more」を削除する方法に関する内容

 #moreって何?

WordPress で投稿一覧ページから「続きを読む」をクリックして投稿を表示した場合にURL末尾につく文字です。

追加される#moreの例

通常のURL : https://blog.webcontent.jp/entry/no-more

more付きの場合 : https://blog.webcontent.jp/entry/no-more#more

削除する方法

#moreを削除するには「functions.php」にフィルタ用のコードを挿入する必要があります。失敗するとサイトが表示できなくなる危険性があるので、心配な方はプラグインの使用をおすすめします。

管理画面 → 外観 → テーマ編集 → functions.php に移動し、次のコードを一番下の「?>」の上に記入する。


function remove_more_jump_link( $link) {
$offset = strpos( $link, '#more-');
if ($offset) {
$end = strpos( $link, '"', $offset);
}
if ($end) {
$link = substr_replace( $link, '', $offset, $end-$offset);
}
return $link;
}
add_filter( 'the_content_more_link', 'remove_more_jump_link');

プラグイン版

functions.phpの内容をプラグイン化したものです。次のリンクからプラグインをダウンロードして、あなたのWordpressに追加してください。

ダウンロード

スポンサーリンク

WordPress

Posted by birdone