previous_posts_link() と next_posts_link() にクラス付加
実装には下記をfunctions.php
に記述し、記述後に表示確認すると前ページへのa
要素に.prev-link"
が、次ページへのa
要素に.next-link
というクラスがそれぞれ付加されているのを確認できます。
※他のクラス名にしたい場合はハイライト部分を任意のものに変更してください。
functions.php
add_filter( 'previous_posts_link_attributes', 'add_prev_posts_link_class' );
function add_prev_posts_link_class() {
return 'class="prev-link"';
}
add_filter( 'next_posts_link_attributes', 'add_next_posts_link_class' );
function add_next_posts_link_class() {
return 'class="next-link"';
}
previous_post_link() と next_post_link() にクラス付加
previous_post_link()
とnext_post_link()
に任意のクラスを付加したい場合は、functions.php
へ下記のように記述します。
記述後に表示確認すると前の投稿へのa
要素に.prev-link"
が、次の投稿へのa
要素に.next-link
というクラスがそれぞれ付加されているのを確認できます。
※他のクラス名にしたい場合はハイライト部分を任意のものに変更してください。
functions.php
add_filter( 'previous_post_link', 'add_prev_post_link_class' );
function add_prev_post_link_class($output) {
return str_replace('<a href=', '<a class="prev-link" href=', $output);
}
add_filter( 'next_post_link', 'add_next_post_link_class' );
function add_next_post_link_class($output) {
return str_replace('<a href=', '<a class="next-link" href=', $output);
}