Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the rocket domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /home/teamikci/subdomain/apsaraaruna.dev/wp-includes/functions.php on line 6114

Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the wordpress-seo domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /home/teamikci/subdomain/apsaraaruna.dev/wp-includes/functions.php on line 6114
wp_pagenavi add attribute to the pagination link - Apsara Aruna
  • Jan 11, 2023

wp_pagenavi add attribute to the pagination link

If you want to add a rel='canonical' attribute to the pagination links generated by the wp_pagenavi plugin, you can use the str_replace() function to replace the <a> tag with a new <a> tag that includes the rel='canonical'attribute.

Here’s an example of how you can do this:

function custom_wp_pagenavi( $html ) {
    $html = str_replace( '<a ', '<a rel="canonical" ', $html );
    return $html;
}
add_filter( 'wp_pagenavi', 'custom_wp_pagenavi' );

This code will replace all the '<a ' in the $html output, with '<a rel="canonical" ' adding the rel attribute, it will add the attribute to all the anchor tags in pagination links

It is important to note that this will only affect the pagination links generated by the wp_pagenavi plugin, not the main URL of the page.

The "rel=canonical" link element is used to tell search engines which version of the content is the original one. It is used to avoid duplicate content, for example, when you have a category page, pagination pages and search pages that have the same content.

Share on: