{"id":2759,"date":"2017-08-11T05:32:28","date_gmt":"2017-08-11T05:32:28","guid":{"rendered":"https:\/\/docs.contentviewspro.com\/?p=2759"},"modified":"2023-12-27T10:32:37","modified_gmt":"2023-12-27T10:32:37","password":"","slug":"add-custom-css-class-post-title","status":"publish","type":"docs","link":"https:\/\/contentviewspro.com\/documentation\/article\/add-custom-css-class-post-title\/","title":{"rendered":"Add custom CSS class to post title"},"content":{"rendered":"<p>To add custom CSS class to all post titles in Views, please add this code to file <strong>functions.php<\/strong> in the theme&#8217;s folder:<\/p>\n<pre style=\"font-size:13px\">\n\/\/ Content Views Pro - add custom class to post title\nadd_filter( 'pt_cv_field_title_class', 'cvp_theme_field_title_class', 100, 1 );\nfunction cvp_theme_field_title_class( $args ) {\n\n\t$custom_class = 'CLASS_NAME_HERE';\n\n\t$args .= ' ' . $custom_class;\n\treturn $args;\n}\n<\/pre>\n<p>If the custom class name is dynamic, for example it is value of a custom field of post, please replace this code:<\/p>\n<pre style=\"font-size:13px\">\n$custom_class = 'CLASS_NAME_HERE';\n<\/pre>\n<p>by this code:<\/p>\n<pre style=\"font-size:13px\">\n# To use custom field value as class name\nglobal $post;\n$meta = get_post_meta( $post->ID );\nif ( !empty( $meta[ 'CUSTOM_FIELD_KEY_HERE' ][ 0 ] ) ) {\n\t$custom_class = $meta[ 'CUSTOM_FIELD_KEY_HERE' ][ 0 ];\n}\n<\/pre>\n<p>(replace <strong>CUSTOM_FIELD_KEY_HERE<\/strong> with your value).<\/p>\n<p>Best regards,<\/p>\n","protected":false},"excerpt":{"rendered":"<p>To add custom CSS class to all post titles in Views, please add this code to file functions.php in the theme&#8217;s folder: \/\/ Content Views Pro &#8211; add custom class to post title add_filter( &#8216;pt_cv_field_title_class&#8217;, &#8216;cvp_theme_field_title_class&#8217;, 100, 1 ); function cvp_theme_field_title_class( $args ) { $custom_class = &#8216;CLASS_NAME_HERE&#8217;; $args .= &#8216; &#8216; . $custom_class; return $args; &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"\" href=\"https:\/\/contentviewspro.com\/documentation\/article\/add-custom-css-class-post-title\/\"> <span class=\"screen-reader-text\">Add custom CSS class to post title<\/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":[47],"doc_tag":[21],"class_list":["post-2759","docs","type-docs","status-publish","hentry","doc_category-customize-css-style","doc_tag-custom-code"],"year_month":"2026-09","word_count":134,"total_views":"1","reactions":{"happy":"0","normal":"0","sad":"0"},"author_info":{"name":"CVP","author_nicename":"cvp","author_url":"https:\/\/contentviewspro.com\/documentation\/author\/cvp\/"},"doc_category_info":[{"term_name":"Customize CSS\/Style","term_url":"https:\/\/contentviewspro.com\/documentation\/cats\/customize-css-style\/"}],"doc_tag_info":[{"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\/2759","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=2759"}],"version-history":[{"count":1,"href":"https:\/\/contentviewspro.com\/documentation\/wp-json\/wp\/v2\/docs\/2759\/revisions"}],"predecessor-version":[{"id":5413,"href":"https:\/\/contentviewspro.com\/documentation\/wp-json\/wp\/v2\/docs\/2759\/revisions\/5413"}],"wp:attachment":[{"href":"https:\/\/contentviewspro.com\/documentation\/wp-json\/wp\/v2\/media?parent=2759"}],"wp:term":[{"taxonomy":"doc_category","embeddable":true,"href":"https:\/\/contentviewspro.com\/documentation\/wp-json\/wp\/v2\/doc_category?post=2759"},{"taxonomy":"doc_tag","embeddable":true,"href":"https:\/\/contentviewspro.com\/documentation\/wp-json\/wp\/v2\/doc_tag?post=2759"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}