skip to Main Content

Inside my archive template, I’m using a pagination.
it is generated by the function paginate_links()

https://developer.wordpress.org/reference/functions/paginate_links/

I try to find out how to implement rel attributes : next and prev inside the links, like this :

<a class="page-numbers" rel="prev" href="mywebsite.fr/blog/page/1/#target">1</a>

<span class="page-numbers current" href="mywebsite.fr/blog/page/2/#target">2</span>

<a class="page-numbers" rel="next" href="mywebsite.fr/blog/page/3/#target">3</a>

Have you ever encountered this problem ? Have you use a hook ?

Thanks for your replies !

2

Answers


  1. You can add rel=prev and rel=next to your paginated links by adding the prev_text and next_text arguments like the following:

    paginate_links(array(
            'prev_text'    => __('previous'),
            'next_text'    => __('next'),
        ));
    
    Login or Signup to reply.
  2. To resolve this, I took the HTML template returned by the function and replaced the string near the class of link, like this:

    {{ paginationHTML|replace({'class="prev' : 'rel="prev" class="prev', 'class="next' : 'rel="next" class="next'}) }}
    

    In my case I’m using twig, but you can easily change that to PHP replace.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search