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
Customize the WP-PageNavi HTML structure - Apsara Aruna
  • Nov 11, 2022

Customize the WP-PageNavi HTML structure

This code will help you to customize WP-PageNavi pagination html structure.

Example -1: Using this you can wrap a and span with li

<?php
add_filter( 'wp_pagenavi', 'ap_pagination', 10, 2 );
 
// customize the PageNavi HTML before it is output
function ap_pagination($html) {
	$out = '';
	//wrap a's and span's in li's
	$out = str_replace("<a","<li><a",$html);    
	$out = str_replace("</a>","</a></li>",$out);
	$out = str_replace("<span","<li><a",$out);   
	$out = str_replace("</span>","</a></li>",$out);
	$out = str_replace("<div class='wp-pagenavi'>","",$out);
	$out = str_replace("</div>","",$out);
 
	return '<ul>'.$out.'</ul> ';
}
?>

Example 2: Add extra attribute to pagination link

add_filter('wp_pagenavi', 'ap_pagination', 10, 2);
function ap_pagination($html)
{
  $out = '';
  $out = str_replace("<a", "<a rel='canonical' ", $html);

  return  $out;
}
Share on: