3.7: How to exclude categories in wp_head() rel prev/next links?
-
Just upgraded to 3.7 and all that seems to be going fine. My question is: How do I exclude categories from appearing in the wp_head()’s rel prev/next links so that they match what my blog is showing to the user on the home page, single posts and so on.
Apparently this stuff is not handled in the theme’s header.php but somewhere deeper in the WP core where it processes wp_head().
FYI, this is what I have currently in my theme’s functions.php file to exclude my categories:
function remove_my_categories( $wp_query ) { // 61 = Daily Tweets, 74 = Testing //global $post; $remove_cat = '-61,-74'; // remove from archives (except category archives), feeds, search, and home page if( is_home() || is_feed() || is_search() || ( is_archive() && !is_category() )) { // if( is_home() || is_feed() || ( is_archive() && !is_category() )) { set_query_var('cat', $remove_cat); //set_query_var('cat', '-' . $testing); //which is merely the more elegant way to write: //$wp_query->set('cat', '-' . $gloss_category); } } add_action('pre_get_posts', 'remove_my_categories' );
Oh yeah, I am using a Twenty Twelve Child Theme with latest updates applied to it as well. In my header.php file I use the following to exclude categories from the prev/next links the user sees:
$mrh_exclude = '61 and 74'; <span class="nav-previous"><?php previous_post_link( '%link', '<span class="meta-nav">' . _x( '←', 'Previous post link', 'twentytwelve' ) . '</span> %title', false, $mrh_exclude ); ?></span> <span class="nav-next"><?php next_post_link( '%link', '%title <span class="meta-nav">' . _x( '→', 'Next post link', 'twentytwelve' ) . '</span>', false, $mrh_exclude ); ?></span>
Thanks for any help,
Mark H.
- The topic ‘3.7: How to exclude categories in wp_head() rel prev/next links?’ is closed to new replies.