• 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( '&larr;', '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( '&rarr;', 'Next post link', 'twentytwelve' ) . '</span>', false, $mrh_exclude ); ?></span>

    Thanks for any help,
    Mark H.

Viewing 1 replies (of 1 total)
  • Thread Starter MarkRH

    (@markrh)

    After doing some searching, I have for the moment just removed those links from being generated by adding the following to my theme’s functions.php:

    // remove rel prev/next links
    remove_action('wp_head', 'start_post_rel_link', 10, 0 );
    remove_action('wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0);

    So, at this point, just need to decide if I want to leave them out or add my own code to exclude the categories.

Viewing 1 replies (of 1 total)
  • The topic ‘3.7: How to exclude categories in wp_head() rel prev/next links?’ is closed to new replies.