Get the current category link
-
Hi! I’m trying to get the current category link because I want to show it into the Open Graph metadata. I’m using a function in functions.php, like this:
If is_category, bla bla…
<meta property="og:url" content=" <?php $the_cat = get_the_category(); $category_link = get_category_link( $the_cat[0]->cat_ID ); ?> <?php echo $category_link ?>" />
.
I have categories and subcategories. So it works right in a subcategory, for example domain.com/science/astrophysics/, but in the main category of science, it shows domain.com/science/astrophysics/ (because the last post of the loop is in the Astrophysics category.
I wish the right URL for each category. Any help? Thanks.
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Get the current category link’ is closed to new replies.