I’m trying to create <div class="cat-hidden categories"></div>
where categories
is a list of the categories the current post is posted in.
When just using the_taxonomies()
, it outputs something like this:
<div class="cat-hidden Job Type: <a href='http://www.cirkut.net/wp/libertyguide/genre/early-career/'>Early-Career</a>, <a href='http://www.cirkut.net/wp/libertyguide/genre/internship/'>Internship</a>, <a href='http://www.cirkut.net/wp/libertyguide/genre/other/'>Other</a>, and <a href='http://www.cirkut.net/wp/libertyguide/genre/web-developmentit/'>Web Development/IT</a>."></div>`
Whereas I want it to output something similar to this:
<div class="cat-hidden Early-Career Internship Web-Development/IT"></div>
That means I’m going to also have to parse the categories that are outputted because I need Web Development/IT
to be Web-Development/IT
or Web-Development-IT
. I’m unsure about the /
being in there because I think CSS doesn’t allow a /
. That’s where you experts come along.
I am very proficient in HTML and CSS, and know some PHP and WordPress, but I don’t know where to begin.
If any more info is needed, please let me know.
Thank you!
you can use
wp_get_post_terms()
to get a list of the post categories and just output the category slug which is already phrased for you, something like this:Just to offer up some different approaches …
Another …
That
wp_list_pluck
function is real handy for these kind of things, avoids the need to do any looping yourself..