Hey there, thanks for the kind words about the theme.
I’d always recommend against hacking the theme directly.
You’re almost always better off creating a child theme or plugin.
To that end, please revert any changes to the theme as we won’t need them here.
Also, the $next_post_btn code isn’t really used and should be removed. Sorry for the false lead.
If you were to dig around in class-tube-pagination.php, you’d find that (unfortunately) the theme doesn’t use (or expose for filtering) the in_same_term, excluded_terms, or taxonomy arguments for get_next_post_link and get_previous_post_link.
This would be a lot easier if it did.
Since it doesn’t, the best approach would be to create a simple plugin.
I’ve put one together below that you can drop into your plugins folder.
It’s nothing glamorous, but based on my quick testing it should do exactly what you need.
Drop a reply with any questions.
——————–
<?php
/*
Plugin Name: .TUBE Prev / Next Post in Term
Author: .TUBE gTLD
Author URI: https://www.get.tube
Version: 1.0.0
Text Domain: tube-prev-next-in-term
License: GPLv3 or later - https://www.gnu.org/licenses/gpl-3.0.html
*/
TUBE_PrevNext_In_Term::init();
class TUBE_PrevNext_In_Term {
public static $instance;
public static function init() {
if ( is_null( self::$instance ) )
self::$instance = new TUBE_PrevNext_In_Term();
return self::$instance;
}
// Constructor
function __construct() {
add_action( 'wp_head', array( $this, 'setup_custom_pagination' ));
}
function setup_custom_pagination() {
global $tube_theme;
// remove action to show the previous / next posts links after the content
remove_action('tube_after_post_content', array( $tube_theme::$tube_pagination, 'prevnext_post_links' ), 100 );
remove_action('tube_before_post_content', array( $tube_theme::$tube_pagination, 'prevnext_post_links' ), 100 );
// add action to show the custom previous / next posts links after the content
add_action('tube_after_post_content', array( $this, 'prevnext_post_links_in_term' ), 100 );
add_action('tube_before_post_content', array( $this, 'prevnext_post_links_in_term' ), 100 );
}
// output the custom prevnext_post_links
function prevnext_post_links_in_term() {
$prevnext_post_links = $this -> get_prevnext_post_links_in_term();
echo wp_kses_post( $prevnext_post_links );
}
// get the prevnext_post_links
function get_prevnext_post_links_in_term() {
// get the current post object
$the_post = get_queried_object();
// get the current post's post type
$post_type_obj = get_post_type_object( $the_post -> post_type );
// get the singular name of the post type
$post_type_name = $post_type_obj->labels->singular_name;
$prev_label_text = sprintf(
'%1$s %2$s',
_x('Previous', 'Pagination: prev / next post links (used on single post page)', 'tube-prev-next-in-term'),
esc_html( $post_type_name )
);
$next_label_text = sprintf(
'%1$s %2$s',
_x('Next', 'Pagination: prev / next post links (used on single post page)', 'tube-prev-next-in-term'),
esc_html( $post_type_name )
);
// get the next post link
$next_post_link = get_next_post_link('%link', '<span class="btn-text">' . $next_label_text . '</span> <span class="btn-icon"><i class="fa fa-chevron-circle-right"></i></span></span>', true);
// get the previous post link
$prev_post_link = get_previous_post_link('%link', '<span class="btn-icon"><i class="fa fa-chevron-circle-left"></i></span> <span class="btn-text">' . $prev_label_text . '</span>', true);
// if neither previous nor next, do nothing
if ( ! $next_post_link && ! $prev_post_link ):
return;
endif;
// generate the prev / next post links HTML
ob_start();
?>
<div class="pagination-wrap pagination-prevnext clearfix">
<?php
if ( $prev_post_link ):
echo $prev_post_link;
endif;
if ( $next_post_link ):
echo $next_post_link;
endif;
?>
</div>
<?php
// grab the output and return
$output = ob_get_clean();
return $output;
}
}