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');
まぁ別にこのままでもいいんだけど、Read moreクリックしたらヘッダーとか上部ナビゲーションとか省略して、記事タイトルに直で飛んで欲しかったりするじゃないですか。特にウチみたいにヘッダーがある程度縦幅とってるサイトなんかだと。
そんな時は上記ソースの7行目にアンカーで飛ばしたい箇所のidを追加すると捗ります。
function remove_more_jump_link($link) {
$offset = strpos($link, '#more-');
if ($offset) {
$end = strpos($link, '"',$offset);
}
if ($end) {
$link = substr_replace($link, '#任意のid', $offset, $end-$offset);
}
return $link;
}
add_filter('the_content_more_link', 'remove_more_jump_link');
こうすることで、Read moreリンクが「example.com/パーマリンク」⇒「example.com/パーマリンク#任意のid」に。