Next/Previous Post text change
-
Hi,
I was wondering to know that if I can change next/previous post text, for example “Next Post” change to “Next Portfolio”.
Also if I can change it Category wise like if it’s “Portfolio” category so it shows “Next Portfolio” & if it’s “Project” category it shows “Next Project”.
Please let me know thanks.
Thanks,
-
Yes, theres a built in filter function for that. (see inside examples.txct in the plugin root) which you add to your functions.php file or similar location (I suggest a child theme)
For your use case, you’ll need to use a conditional check for modifying the text on a per category use case.
Something like: (not tested on a live environment so please check the code)
function wp_post_nav_translate( $translated_text, $text, $domain ) {
//project category
if (is_category(‘project’)) {
switch ( $translated_text ) {
case ‘Category: ‘ :
$translated_text = __( ‘Project Category: ‘, ‘wp-post-nav’ );
break;
case ‘Previous Post’ :
$translated_text = __( ‘Previous Projext: ‘, ‘wp-post-nav’ );
break;
case ‘Next Post’ :
$translated_text = __( ‘Next Project: ‘, ‘wp-post-nav’ );
break;
}
}
//portfolio category
elseif (is_category(‘portfolio’)) {
switch ( $translated_text ) {
case ‘Category: ‘ :
$translated_text = __( ‘Portfolio Category: ‘, ‘wp-post-nav’ );
break;
case ‘Previous Post’ :
$translated_text = __( ‘Previous Portfolio: ‘, ‘wp-post-nav’ );
break;
case ‘Next Post’ :
$translated_text = __( ‘Next Portfolio: ‘, ‘wp-post-nav’ );
break;
}
}
return $translated_text;
}
add_filter( ‘gettext’, ‘wp_post_nav_translate’, 20, 3 );Hi John,
I have tried this code but it is not working nothing changed. Just to add up I am using custom post type so if there is any concern with that.
Thanks,
Ah so that does make a difference as the above is for the default ‘post’ post type.
You need to adjust it for your custom post types so instead of using the is_category wordpress filter, you need to use a post type check.
if ( ‘portfolio’ == get_post_type() ) {
}elsif ( ‘project’ == get_post_type() {
}Hi John,
We only use Tags.
How can we change from Categogies to Tags?
Please help.
Thanks,
TonyHi @quanvan
Thats not currently possible and is a really limited use case to work that way.
It would require a customised solution as getting posts of the same tag is a custom query and not something that can easily be built in to the plugin.
John
Hi,
Thanks for your reply.
Can you add 2 choice:
1. Categories
2. TagsI don’t know well English so i hope you will understand mine.
Thanks,
Tuan NguyenHi John,
I have one custom post type & 2 different categories so I used this code but it is not working please check this code:
$type = get_post_type(); if ($type = 'astra-portfolio') { function wp_post_nav_translate( $translated_text, $text, $domain ) { //Showreel category if (is_category('showreel')) { switch ( $translated_text ) { case 'Category: ' : $translated_text = __( 'Showreel Category: ', 'wp-post-nav' ); break; case 'Previous Post' : $translated_text = __( 'Previous Showreel: ', 'wp-post-nav' ); break; case 'Next Post' : $translated_text = __( 'Next Showreel: ', 'wp-post-nav' ); break; } } //Photographic category elseif (is_category('photographic')) { switch ( $translated_text ) { case 'Category: ' : $translated_text = __( 'Photographic Category: ', 'wp-post-nav' ); break; case 'Previous Post' : $translated_text = __( 'Previous Photographic: ', 'wp-post-nav' ); break; case 'Next Post' : $translated_text = __( 'Next Photographic: ', 'wp-post-nav' ); break; } } return $translated_text; } add_filter( 'gettext', 'wp_post_nav_translate', 20, 3 ); }Please let me know.
Thanks,
The topic ‘Next/Previous Post text change’ is closed to new replies.