Archived topic
Disable next/previous post
15 replies · Started by miguel on May 18, 2017
Hi,
I would like to delete the previous/next post link. I know how to do it with CSS, but I don't want to hide it, I want to remove it at all for SEO purposes. I don't want Google to crawl these links.
I recently purchased the premium theme and I thought it would be possible to remove it, but it is not. Is there any way to do it?
Thanks
Miguel
Hi Miguel,
This should do it: https://gist.github.com/generatepress/81709146251f7a9b645a
Adding PHP: https://docs.generatepress.com/article/adding-php/
Hi Leo,
This is exactly what I was looking for.
Thank you very much.
Miguel
Credit to Tom :) Glad I could help!
Hi, I'm trying to do the same. Where do I place the code mentioned above?
See the adding PHP link here: https://generatepress.com/forums/topic/disable-nextprevious-post/#post-320444
Hey,
I have installed Code snippet plugin and inserted php code in it.
Activated it, but nothing happens. Previous/next posts are still there.
Is the code mentioned above still relevant?
Thanks!
Hi there,
you can disable the single post navigation in Customizer > Layout > Blog --> Single: Post Navigation.
Make sure you have the Blog module activated in Appearance > GeneratePress.
Hey David,
I have Post navigation disabled, but there are still image links to previous/next post.
For example: http://hupi.si/2018/09/20/aside-for-widgets/
This element:
What now?
The Dispatch site uses a custom function for that. Go to Appearance > Elements and delete ( or save as a draft ) the Custom Post Navigation hook element.
It works.
Thanks much! :)
You're welcome
where to I add below code to disable previous/next link at footer?
if ( ! function_exists( 'generate_content_nav' ) ) :
/**
* Display navigation to next/previous pages when applicable
*/
function generate_content_nav( $nav_id ) {
global $wp_query, $post;
// Don't print empty markup on single pages if there's nowhere to navigate.
if ( is_single() ) {
$previous = ( is_attachment() ) ? get_post( $post->post_parent ) : get_adjacent_post( false, '', true );
$next = get_adjacent_post( false, '', false );
if ( ! $next && ! $previous )
return;
}
// Don't print empty markup in archives if there's only one page.
if ( $wp_query->max_num_pages < 2 && ( is_home() || is_archive() || is_search() ) )
return;
$nav_class = ( is_single() ) ? 'post-navigation' : 'paging-navigation';
?>
<nav role="navigation" id="<?php echo esc_attr( $nav_id ); ?>" class="<?php echo $nav_class; ?>">
<h6 class="screen-reader-text"><?php _e( 'Post navigation', 'generate' ); ?></h6>
<?php if ( $wp_query->max_num_pages > 1 && ( is_home() || is_archive() || is_search() ) ) : // navigation links for home, archive, and search pages ?>
<?php if ( get_next_posts_link() ) : ?>
<?php endif; ?>
<?php if ( get_previous_posts_link() ) : ?>
<?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', __( '← Previous', 'generatepress' ) ),
'next_text' => apply_filters( 'generate_next_link_text', __( 'Next →', 'generatepress' ) ),
) );
}
do_action('generate_paging_navigation'); ?>
<?php endif; ?>
</nav><!-- #<?php echo esc_html( $nav_id ); ?> -->
<?php
}
endif; // generate_content_nav
Hi there,
i replied here to that question:
https://generatepress.com/forums/topic/nextprevious-post-links-on-cpt/#post-998888
Hello,
When I insert this code "Remove next/previous post links completely" in code snippets, it tells me
The code snippet has been disabled due to an error on line 6: Cannot redeclare function generate_content_nav.
Thanks :)