If WordPress get category link returns paged address of a category


You may be trying to have your archive template displaying a header with the current category, ignoring secondary categories your posts may belong too, and also ignoring paged results, linking always to the “home page” of the main category. For example, if you open the 4th page of the “Scripts” category containing 10 posts that belong also to a “WordPress” category,

* if you use single_cat_title you will get the title of the main category (“Scripts”), but unlinked,

* if you use get_category_link($category_id) you will get the main category href, but the link will refer to the current page (e.g. yourdomain/category/scripts/page/4/, or yourdomain/?cat=22&paged=4,

* if you use the_category(”), then you will have a link to the first, home, page of your category, but also all categories that these posts belong to will be displayed, in our case both the “Scripts” and the “WordPress” categories, in the header of your archives.

Here is a code you can use to have only the main category as a header, and this linking to its home page ignoring paged results:

<?php $link = get_category_link( get_cat_ID( single_cat_title('',false) ) ); ?>
<a href="<?php echo $link; ?>" title="<?php single_cat_title(); ?>">
<?php single_cat_title(); ?></a>