Archived topic
Changing post navigation text to NEXT instead of TITLE
10 replies · Started by manaadiar on November 23, 2018
Hi there.. Please see this screen shot..I am using a child theme.. While I can change style using CSS, I want to know which file I need to copy from parent theme to amend the post navigation to show NEXT or PREVIOUS instead of the actual title like it is showing now..
Also I would like the PREVIOUS to show at left edge of the block and NEXT on the right edge removing the line break/wrap within the block..
I want to make changes in the child theme as I don't want this change to disappear when there are theme updates to parent..

To change the text, add these functions:
add_filter( 'next_post_link', function( $output, $format, $link, $post ) {
if ( ! $post ) {
return '';
}
return sprintf(
'<div class="nav-next"><span class="next"><a href="%1$s" title="%2$s">Next</a></span></div>',
get_permalink( $post ),
$post->post_title
);
}, 10, 4 );
add_filter( 'previous_post_link', function( $output, $format, $link, $post ) {
if ( ! $post ) {
return '';
}
return sprintf(
'<div class="nav-previous"><span class="prev"><a href="%1$s" title="%2$s">Previous</a></span></div>',
get_permalink( $post ),
$post->post_title
);
}, 10, 4 );
To make them appear on either side, you can do this:
.post-navigation {
display: flex;
}
.nav-previous {
margin-right: auto;
}
.nav-next .next:before {
display: none;
}
.nav-next .next:after {
font-family: GeneratePress;
content: "\f105";
text-decoration: inherit;
position: relative;
margin-left: .6em;
width: 13px;
text-align: center;
display: inline-block;
-moz-osx-font-smoothing: grayscale;
-webkit-font-smoothing: antialiased;
font-style: normal;
font-variant: normal;
text-rendering: auto;
line-height: 1;
speak: none;
}
That worked perfectly, thanks.. Can I have a Title Tip as well which will show the title of the post..
Just adjusted my instructions above: https://generatepress.com/forums/topic/changing-post-navigation-text-to-next-instead-of-title/#post-737583
Hi Tom, the title tip is showing but the Previous and Next has a break now like it was previously..

Ah, sorry about that! I just adjusted the functions above :)
Is it possible to have NEXT instead of TITLE activated for a particular post category only? The rest of the categories to have the original names of posts?
Hi there,
in the PHP Snippet that Tom provided you will see two instances of:
if ( ! $post ) {
Change this to:
if ( ! $post || ! in_category('your_category_slug') ) {
Change the your_category_slug to match the one where you want it to display Next/Previous instead of the title.
Thanks for that David. That worked for that particular category but the other categories now don't show any post navigation at all - this area is blank?
Aah this is a very old way of changing these - a lot has changed since then.
Could you raise a new topic where we can start afresh
Will do David thanks.