Title

PHP Shortcode list categories and/or tags

description

Works in combination with the 'Code Snippets' plugin. Add the code as a HTML content snippet, select 'Evaluate PHP code' and use the generated shortcode in a template or page.

Published 2022-09-08

Modified 2022-09-08

content

				
					<?php
$categories = get_categories();
foreach($categories as $category) {
echo '<span class="' . $category->slug . ' some-class"><span class="another-class">' . $category->name . '</span><span class="yet-another-class">' . $category->description . '</span></span>';
}
?>
				
			
				
					<?php
$tags = get_tags();
foreach($tags as $tag) {
echo '<span class="' . $tag->slug . ' some-class"><span class="another-class">' . $tag->name . '</span><span class="yet-another-class">' . $tag->description . '</span></span>';
}
?>
				
			
				
					span {display:inline-block;margin-right:12px;font-weight:bold;}
				
			

Output of the shortcode for tags:

accordionanimationbackendcode-snippetsconditionalscsscustom postselementorfrontendhtmljetsmartfiltersjs-jquerylibrary/pluginpagesphppostsscrolluiwoocommerce

Sources & References