Title: Cannot redeclare the_posts_navigation() &#8211; link-template.php
Last modified: August 31, 2016

---

# Cannot redeclare the_posts_navigation() – link-template.php

 *  Resolved [Argumentum](https://wordpress.org/support/users/argumentum0/)
 * (@argumentum0)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/cannot-redeclare-the_posts_navigation-link-templatephp/)
 * Hello,
 * I am trying to use WP-PageNavi with the Gazette theme ([https://wordpress.org/themes/gazette/](https://wordpress.org/themes/gazette/)).
 * In Gazette, the calls to `next_posts_link()` and `previous_posts_link()` are 
   located in the file `\inc\template-tags.php` (under `function the_posts_navigation()`).
   In this file, `the_posts_navigation()` is a “pluggable” function (it is enclosed
   by `if ( ! 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. “Since `the_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://wordpress.org/plugins/code-snippets/](https://wordpress.org/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 /[redacted]/
   > public_html/wp-includes/link-template.php:2462)**
 * Interestingly, the problem is related to the file `public_html/wp-includes/link-
   template.php`, not a theme file.
 * What should I do to use WP-PageNavi in my theme?
 * Thanks in advance.
 * [https://wordpress.org/plugins/wp-pagenavi/](https://wordpress.org/plugins/wp-pagenavi/)

Viewing 7 replies - 1 through 7 (of 7 total)

 *  Plugin Author [Lester Chan](https://wordpress.org/support/users/gamerz/)
 * (@gamerz)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/cannot-redeclare-the_posts_navigation-link-templatephp/#post-7136544)
 * This looks like a theme problem rather than a plugin one. You should contact 
   your theme author about it. Might be the order of the_posts_navigation() loaded
   incorrect and hence the problem. I am not sure, the best person to ask is your
   theme author.
 *  Thread Starter [Argumentum](https://wordpress.org/support/users/argumentum0/)
 * (@argumentum0)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/cannot-redeclare-the_posts_navigation-link-templatephp/#post-7136546)
 * Thanks for your prompt answer. I am already waiting for a response from the theme
   author, but I thought that perhaps the problem wasn’t exactly theme-related, 
   since the error mentions the function in the file `public_html/wp-includes/link-
   template.php`.
 * I’ll wait for a response from them.
 *  Thread Starter [Argumentum](https://wordpress.org/support/users/argumentum0/)
 * (@argumentum0)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/cannot-redeclare-the_posts_navigation-link-templatephp/#post-7136739)
 * I got this all wrong. This is not a theme problem.
 * The function `the_posts_navigation` in my theme is actually doing nothing. To
   confirm that, I removed the function from the theme file, and the posts navigation
   on my website is still working with no problems.
 * So my website is actually using the function `the_posts_navigation` from `public_html/
   wp-includes/link-template.php`, which is a core file.
 * WP-PageNavi instructions says:
 * > In your theme, you need to find calls to next_posts_link() and previous_posts_link()
   > and replace them.
 * But, in my website, the only file with these calls is `link-template.php` ([https://core.trac.wordpress.org/browser/tags/4.4.2/src/wp-includes/link-template.php](https://core.trac.wordpress.org/browser/tags/4.4.2/src/wp-includes/link-template.php)).
 * What should I do to use WP-PageNavi in my site, then?
 * Thanks in advance.
 *  Plugin Author [Lester Chan](https://wordpress.org/support/users/gamerz/)
 * (@gamerz)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/cannot-redeclare-the_posts_navigation-link-templatephp/#post-7136748)
 * Find and replace the text in your theme `next_posts_link()` with `wp_pagenavi()`?
 *  Thread Starter [Argumentum](https://wordpress.org/support/users/argumentum0/)
 * (@argumentum0)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/cannot-redeclare-the_posts_navigation-link-templatephp/#post-7136750)
 * The problem is that `next_posts_link()` is not present in any of my theme files.
 * The only file (in my website) that I could find `next_posts_link()` and `previous_posts_link()`
   is `public_html/wp-includes/link-template.php`, which is a core file.
 * Here is how `link-template.php` looks: [https://core.trac.wordpress.org/browser/tags/4.4.2/src/wp-includes/link-template.php](https://core.trac.wordpress.org/browser/tags/4.4.2/src/wp-includes/link-template.php)
 * And here is my `index.php`. It simply calls `the_posts_navigation()`.
 *     ```
       <?php
       /**
        * The main template file.
        *
        * This is the most generic template file in a WordPress theme
        * and one of the two required files for a theme (the other being style.css).
        * It is used to display a page when nothing more specific matches a query.
        * E.g., it puts together the home page when no home.php file exists.
        * Learn more: http://codex.wordpress.org/Template_Hierarchy
        *
        * @package Gazette
        */
   
       get_header(); ?>
   
       <?php
       	if ( is_home() ) {
       		// Include the featured content template.
       		get_template_part( 'featured-content' );
       	}
       ?>
   
       	<div id="primary" class="content-area">
       		<main id="main" class="site-main" role="main">
   
       		<?php if ( have_posts() ) : ?>
   
       			<?php /* Start the Loop */ ?>
       			<?php while ( have_posts() ) : the_post(); ?>
   
       				<?php
       					/* Include the Post-Format-specific template for the content.
       					 * If you want to override this in a child theme, then include a file
       					 * called content-___.php (where ___ is the Post Format name) and that will be used instead.
       					 */
       					get_template_part( 'content', get_post_format() );
       				?>
   
       			<?php endwhile; ?>
   
       			<?php the_posts_navigation(); ?>
   
       		<?php else : ?>
   
       			<?php get_template_part( 'content', 'none' ); ?>
   
       		<?php endif; ?>
   
       		</main><!-- #main -->
       	</div><!-- #primary -->
   
       <?php get_footer(); ?>
       ```
   
 *  Plugin Author [Lester Chan](https://wordpress.org/support/users/gamerz/)
 * (@gamerz)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/cannot-redeclare-the_posts_navigation-link-templatephp/#post-7136751)
 * Replace
 *     ```
       <?php the_posts_navigation(); ?>
       ```
   
 * With
 *     ```
       <nav class="navigation posts-navigation" role="navigation">
       		<h2 class="screen-reader-text"><?php _e( 'Posts navigation', 'gazette' ); ?></h2>
       		<div class="nav-links">
       			<?php wp_pagenavi(); ?>
       		</div><!-- .nav-links -->
       	</nav><!-- .navigation -->
       	<?php
       ```
   
 * That is probably the best I can do since I am not using your theme. The best 
   person to ask is really your theme author.
 *  Thread Starter [Argumentum](https://wordpress.org/support/users/argumentum0/)
 * (@argumentum0)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/cannot-redeclare-the_posts_navigation-link-templatephp/#post-7136757)
 * This worked! Thanks a lot!

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Cannot redeclare the_posts_navigation() – link-template.php’ is closed
to new replies.

 * ![](https://ps.w.org/wp-pagenavi/assets/icon.svg?rev=977997)
 * [WP-PageNavi](https://wordpress.org/plugins/wp-pagenavi/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-pagenavi/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-pagenavi/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-pagenavi/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-pagenavi/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-pagenavi/reviews/)

## Tags

 * [function](https://wordpress.org/support/topic-tag/function/)
 * [link-template.php](https://wordpress.org/support/topic-tag/link-template-php/)
 * [navigation](https://wordpress.org/support/topic-tag/navigation/)
 * [redeclare](https://wordpress.org/support/topic-tag/redeclare/)
 * [snippet](https://wordpress.org/support/topic-tag/snippet/)

 * 7 replies
 * 2 participants
 * Last reply from: [Argumentum](https://wordpress.org/support/users/argumentum0/)
 * Last activity: [10 years, 2 months ago](https://wordpress.org/support/topic/cannot-redeclare-the_posts_navigation-link-templatephp/#post-7136757)
 * Status: resolved