-
Hi,
I would like to completely replace current navigation links (next and prev post) within blog single template. Is there any function or hook that I can use to add my own code for this section?
I would like to add date and some meta fields together with post title, but just need a function or hook in charge for navigation.
Thanks!
-
Hi there,
Is there any function or hook that I can use to add my own code for this section
What kind of code are you referring to?
If you want to create custom paginations, you can use the block element – post navigation.
https://docs.generatepress.com/article/block-element-post-navigation/Let me know if I miss anything 🙂
-
I’m not using blocks.. I need some type of hook or function to completely customise this part from child theme functions.php:
<nav <?php generate_do_attr( 'post-navigation', array( 'id' => esc_attr( $nav_id ) ) ); ?>> <?php if ( is_single() ) : // navigation links for single posts. $post_navigation_args = apply_filters( 'generate_post_navigation_args', array( 'previous_format' => '<div class="nav-previous">' . generate_get_svg_icon( 'arrow-left' ) . '<span class="prev">%link</span></div>', 'next_format' => '<div class="nav-next">' . generate_get_svg_icon( 'arrow-right' ) . '<span class="next">%link</span></div>', 'link' => '%title', 'in_same_term' => apply_filters( 'generate_category_post_navigation', false ), 'excluded_terms' => '', 'taxonomy' => 'category', ) ); previous_post_link( $post_navigation_args['previous_format'], $post_navigation_args['link'], $post_navigation_args['in_same_term'], $post_navigation_args['excluded_terms'], $post_navigation_args['taxonomy'] ); next_post_link( $post_navigation_args['next_format'], $post_navigation_args['link'], $post_navigation_args['in_same_term'], $post_navigation_args['excluded_terms'], $post_navigation_args['taxonomy'] ); elseif ( is_home() || is_archive() || is_search() ) : // navigation links for home, archive, and search pages. if ( get_next_posts_link() ) : ?> <div class="nav-previous"> <?php generate_do_svg_icon( 'arrow' ); ?> <span class="prev" title="<?php esc_attr_e( 'Previous', 'generatepress' ); ?>"><?php next_posts_link( __( 'Older posts', 'generatepress' ) ); ?></span> </div> <?php endif; if ( get_previous_posts_link() ) : ?> <div class="nav-next"> <?php generate_do_svg_icon( 'arrow' ); ?> <span class="next" title="<?php esc_attr_e( 'Next', 'generatepress' ); ?>"><?php previous_posts_link( __( 'Newer posts', 'generatepress' ) ); ?></span> </div> <?php endif; if ( function_exists( 'the_posts_pagination' ) ) { the_posts_pagination( array( 'mid_size' => apply_filters( 'generate_pagination_mid_size', 1 ), 'prev_text' => apply_filters( 'generate_previous_link_text', sprintf( /* translators: left arrow */ __( '%s Previous', 'generatepress' ), '<span aria-hidden="true">←</span>' ) ), 'next_text' => apply_filters( 'generate_next_link_text', sprintf( /* translators: right arrow */ __( 'Next %s', 'generatepress' ), '<span aria-hidden="true">→</span>' ) ), 'before_page_number' => sprintf( '<span class="screen-reader-text">%s</span>', _x( 'Page', 'prepends the pagination page number for screen readers', 'generatepress' ) ), ) ); } /** * generate_paging_navigation hook. * * @since 0.1 */ do_action( 'generate_paging_navigation' ); endif; ?> </nav>With link I want to add some custom meta and other items…
-
Fernando
Hi Adaba,
To clarify, are you looking to create something like what’s created here: https://docs.generatepress.com/article/block-element-post-navigation/ – but through custom code?
-
exactly, since I’m not using blocks.. just need some hook or function that will access navigation part so I can add my own code there…
-
Fernando
I see. The default one can be disabled through Appearance > Customize > Layout > Blog. Reference:
Then, you can hook your code through a Hook Element hooked to
after_contentor somewhere else you prefer. Reference: https://docs.generatepress.com/article/hooks-visual-guide/#single-post -
Ok that makes sense.. I will try that approach.. Thanks
-
Fernando
You’re welcome, Adaba!
- You must be logged in to reply to this topic.