Site logo

[Resolved] Add Pagenavi and remove (not hide) generatepress navigation

Home Forums Support [Resolved] Add Pagenavi and remove (not hide) generatepress navigation

Home Forums Support Add Pagenavi and remove (not hide) generatepress navigation

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #2275832
    MKH – Cyril

    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

    #2276362
    David
    Staff
    Customer Support

    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;
    } );
    #2276987
    MKH – Cyril

    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 ^^

    #2277049
    David
    Staff
    Customer Support

    Jeez … i must have been sleeping when i wrote that **** – my sincere apologies 🙂

    I have updated the code above.

    #2277054
    MKH – Cyril

    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;
    } );
    #2277126
    David
    Staff
    Customer Support

    I have redeemed myself lol

    Glad to be of help

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.