Created
September 7, 2016 08:35
-
-
Save adamrosloniec/58467267db06603dca73ff222e4b2e50 to your computer and use it in GitHub Desktop.
Wordpress with ACF - add background color to category / categories
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function add_blog_category_color(){ | |
$categories = get_categories(array( 'hide_empty' => 0, )); | |
if ( ! empty( $categories ) ) { | |
echo '<style type="text/css">'; | |
foreach( $categories as $category ) { | |
$category_taxonomy = $category->taxonomy; | |
$category_id = $category->term_id; | |
$category_slug = $category->slug; | |
$category_color = get_field('blog_category_color',$category_taxonomy . '_' . $category_id); | |
if (!empty($category_color)) { | |
echo '.blog-category-color--' . $category_slug . '{background-color:' . $category_color . '!important}'; | |
} | |
} | |
echo '</style>'; | |
} | |
} | |
add_action('wp_head','add_blog_category_color'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment