{"id":2319,"date":"2017-10-10T08:41:12","date_gmt":"2017-10-10T08:41:12","guid":{"rendered":"http:\/\/docs.contentviewspro.com\/?p=2319"},"modified":"2023-12-28T12:24:08","modified_gmt":"2023-12-28T12:24:08","password":"","slug":"add-taxonomy-term-slug-category-tag-custom-to-posts-class","status":"publish","type":"docs","link":"https:\/\/contentviewspro.com\/documentation\/article\/add-taxonomy-term-slug-category-tag-custom-to-posts-class\/","title":{"rendered":"Add category\/tag\/taxonomy term to HTML class of posts in grid"},"content":{"rendered":"<p>To add taxonomy term slug (category, tag, custom) as HTML class of the wrapper div of each item in the grid, please add this code to file <strong>functions.php<\/strong> of your active theme:<\/p>\n<pre style=\"font-size:13px\">\n\/\/ Content Views Pro - Add taxonomy term name to post's class\nadd_filter( 'pt_cv_content_item_class', 'cvp_theme_term_name_as_class', 100, 2 );\nfunction cvp_theme_term_name_as_class( $args, $post_id ) {\n\t$taxonomies\t = get_taxonomies( '', 'names' );\n\t$terms\t\t = wp_get_object_terms( $post_id, $taxonomies );\n\tforeach ( $terms as $term ) {\n\t\t$args[] = sanitize_html_class( \"cvp-term-{$term->taxonomy}-{$term->slug}\" );\n\t}\n\n\treturn $args;\n}\n<\/pre>\n<p>Best regards,<\/p>\n","protected":false},"excerpt":{"rendered":"<p>To add taxonomy term slug (category, tag, custom) as HTML class of the wrapper div of each item in the grid, please add this code to file functions.php of your active theme: \/\/ Content Views Pro &#8211; Add taxonomy term name to post&#8217;s class add_filter( &#8216;pt_cv_content_item_class&#8217;, &#8216;cvp_theme_term_name_as_class&#8217;, 100, 2 ); function cvp_theme_term_name_as_class( $args, $post_id ) &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"\" href=\"https:\/\/contentviewspro.com\/documentation\/article\/add-taxonomy-term-slug-category-tag-custom-to-posts-class\/\"> <span class=\"screen-reader-text\">Add category\/tag\/taxonomy term to HTML class of posts in grid<\/span> Read More &raquo;<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"site-sidebar-layout":"default","site-content-layout":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","footnotes":""},"doc_category":[25],"doc_tag":[17,21],"class_list":["post-2319","docs","type-docs","status-publish","hentry","doc_category-adjustment","doc_tag-category-tag-taxonomy","doc_tag-custom-code"],"year_month":"2026-09","word_count":98,"total_views":"3","reactions":{"happy":"0","normal":"1","sad":"0"},"author_info":{"name":"CVP","author_nicename":"cvp","author_url":"https:\/\/contentviewspro.com\/documentation\/author\/cvp\/"},"doc_category_info":[{"term_name":"Adjustment","term_url":"https:\/\/contentviewspro.com\/documentation\/cats\/adjustment\/"}],"doc_tag_info":[{"term_name":"category tag taxonomy","term_url":"https:\/\/contentviewspro.com\/documentation\/tags\/category-tag-taxonomy\/"},{"term_name":"custom PHP code","term_url":"https:\/\/contentviewspro.com\/documentation\/tags\/custom-code\/"}],"_links":{"self":[{"href":"https:\/\/contentviewspro.com\/documentation\/wp-json\/wp\/v2\/docs\/2319","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/contentviewspro.com\/documentation\/wp-json\/wp\/v2\/docs"}],"about":[{"href":"https:\/\/contentviewspro.com\/documentation\/wp-json\/wp\/v2\/types\/docs"}],"author":[{"embeddable":true,"href":"https:\/\/contentviewspro.com\/documentation\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/contentviewspro.com\/documentation\/wp-json\/wp\/v2\/comments?post=2319"}],"version-history":[{"count":1,"href":"https:\/\/contentviewspro.com\/documentation\/wp-json\/wp\/v2\/docs\/2319\/revisions"}],"predecessor-version":[{"id":5334,"href":"https:\/\/contentviewspro.com\/documentation\/wp-json\/wp\/v2\/docs\/2319\/revisions\/5334"}],"wp:attachment":[{"href":"https:\/\/contentviewspro.com\/documentation\/wp-json\/wp\/v2\/media?parent=2319"}],"wp:term":[{"taxonomy":"doc_category","embeddable":true,"href":"https:\/\/contentviewspro.com\/documentation\/wp-json\/wp\/v2\/doc_category?post=2319"},{"taxonomy":"doc_tag","embeddable":true,"href":"https:\/\/contentviewspro.com\/documentation\/wp-json\/wp\/v2\/doc_tag?post=2319"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}