Site logo

Archived topic

Add Pagenavi and remove (not hide) generatepress navigation

5 replies · Started by MKH - Cyril on July 7, 2022

Viewing posts 1–6 of 6

hi :)

i want to add pagenavi, found the hook to do it, and it works.

add_action('generate_paging_navigation','generate_pagenavi_integration');
function generate_pagenavi_integration()
{
    wp_pagenavi();
}

i found the css hook to hide the original navigation too

.page-numbers {
      display: none;
}

but what i want is to remove the original navigation code, for better seo results, not just hide it.

is it possible ? if yes, how ? :)

thanks in advance

Hi there,

try this instead:

add_action( 'generate_after_main_content', function() {
    if ( function_exists( 'wp_pagenavi' ) ) {
        wp_pagenavi();
    }
} );

add_filter( 'generate_show_post_navigation', function( $show ) {
    if ( !is_single() ) {
	return false;	
    }
    return $show;
} );

Thanks for helping.

So the first hook adds the pagenavigation after each post on archives, so 10 navigations on each page ^^
So not good :(

And second one generates a critical error on website ^^

Jeez ... i must have been sleeping when i wrote that **** - my sincere apologies :)

I have updated the code above.

haha, no prob, because YOU ROCK !

it's working like a charm, thanks a lot

If someone want the full code, i updated it to keep the style, maybe it can be improved, but it works ;)

// Add wp-pagenavi, removes native navigation, keeps CSS fine

function beforewppagenavi() 
{
    echo '<nav id="nav-below" class="paging-navigation" aria-label="Archive Page">';    
}

function afterwppagenavi() 
{
    echo '</nav>';    
}

add_action( 'generate_after_main_content', function() {
    if ( function_exists( 'wp_pagenavi' ) ) {
        beforewppagenavi();
		wp_pagenavi();
		afterwppagenavi();
    }
} );

add_filter( 'generate_show_post_navigation', function( $show ) {
    if ( !is_single() ) {
	return false;	
    }
    return $show;
} );

I have redeemed myself lol

Glad to be of help

This archived topic is closed to new replies.