Skip to content

Instantly share code, notes, and snippets.

@akshay-sihag
akshay-sihag / primary_category_shortcode.php
Created January 14, 2020 21:04
Display Primary Category (Yoast's WordPress SEO) with the help of a shortcode
// Creating Shortcode to display Yoast SEO Primary Category
// Add Shortcode
function get_yoast_primary_cat() {
$category = get_the_category();
$useCatLink = true;
// If post has a category assigned.
if ($category){
$category_display = '';
@jawinn
jawinn / primary_category.php
Last active December 8, 2022 21:42
Display Primary Category (Yoast's WordPress SEO)
<?php
/**
* Get the Yoast primary category from its post meta value, and displays it, with HTML markup.
* If there is no primary category set, it displays the first assigned category.
*
* @param boolean $useCatLink Whether to link the category, if it exists
* @return void
*/
function yourtheme_display_yoast_primary_category( $useCatLink = true ) {