Facebook really loves to play Popularity Police. If you don’t like enough of a Page’s posts, they stop showing in […]
Displaying Custom WordPress Taxonomy List Items Without the Links
April 21st, 2011
Or: How to Strip <A> Tags From get_the_term_list
Okay, this one is a bit obscure and not terribly complex, but it took me a minute to solve, so here it is for the rest of the world.
I was working on a WordPress custom taxonomy as a way to store and display useful information about a post. Specifically, I was creating a “Venue” type to store nightclub names which could then be displayed easily throughout the theme’s code, as well as inserted via shortcode.
Creating the Custom Taxonomy
Creating the taxonomy itself wasn’t really that hard, and isn’t the main subject of this post, but for the sake of completeness, I’ll cover that briefly first.
In the above code, I’m registering the taxonomy “your-custom-taxonomy-name” to attach to pages (as opposed to posts). I’m declaring it to be a hierarchical type, like WordPress’ native Categories, with the label “Taxo Name” showing up as the label above it in the admin. The “query_var” tells whether it should apply to custom post types, and “rewrite=>true” allows for pretty URLs such as “mysite.com/your-custom-taxonomy-name/item” instead of the default “mysite.com/?your-custom-taxonomy-name=item”.
This declaration in your functions.php file will register the taxonomy with the database and put a new meta box next to your pages.
For more info on custom taxonomies and how they work, check out custom taxonomies in the WordPress codex.
Outputting the Taxonomies Without Links
Now, I wanted to output the taxonomy info into the theme; i.e., I wanted the theme to display the name of the venue in various places. My only problem was that while the most obvious choice for this was WP function “get_the_term_list()“, it outputs the taxonomy terms as links, wrapped in <a> tags. After some mucking around, I discovered two possible solutions. Keep Reading