Function the_posts_navigation() on child theme
-
Hello,
I am trying to use the plugin WP-PageNavi (https://www.ads-software.com/plugins/wp-pagenavi/) to customise the page navigation links.
To use it, I have to replace the calls to
next_posts_link()
andprevious_posts_link()
. In Gazette, they are located in the file\inc\template-tags.php
(functionthe_posts_navigation()
).From what I learnt from this thread (https://www.ads-software.com/support/topic/post-navigation-background-images?replies=6),
the_posts_navigation()
is a “pluggable” function (it is enclosed byif ( ! function_exists( 'the_posts_navigation' ) ) :
).So I tried to simply copy the function
the_posts_navigation()
to my child theme and replace the necessary lines in order to use WP-PageNavi. “Sincethe_posts_navigation()
is a pluggable function,” I thought, “I won’t have to do anything else”.Unfortunately, I was wrong. It’s not working.
I use the plugin Code Snippets (https://www.ads-software.com/plugins/code-snippets/) to manage my custom snippets, and when I try to activate the snippet below…
function the_posts_navigation() { // Don't print empty markup if there's only one page. if ( $GLOBALS['wp_query']->max_num_pages < 2 ) { return; } ?> <nav class="navigation posts-navigation" role="navigation"> <h2 class="screen-reader-text"><?php _e( 'Posts navigation', 'gazette' ); ?></h2> <div class="nav-links"> <?php if ( get_next_posts_link() ) : ?> <?php wp_pagenavi(); ?> <?php endif; ?> <?php if ( get_previous_posts_link() ) : ?> <?php wp_pagenavi(); ?> <?php endif; ?> </div><!-- .nav-links --> </nav><!-- .navigation --> <?php }
I get this error:
The code snippet you are trying to save produced a fatal error on line 22:
Cannot redeclare the_posts_navigation() (previously declared in /home/[redacted]/public_html/wp-includes/link-template.php:2462)What should I do to customise
the_posts_navigation()
on my child theme so I can use WP-PageNavi?Thanks again!
- The topic ‘Function the_posts_navigation() on child theme’ is closed to new replies.