Add Color Picker To Edit Category Screen To Set Color For Posts In Each Category

This code adds a color picker to the Edit Category screen which enables you to change colors for different elements on single posts in each category.

This code has been written in response to the following question from a registered user :

“I was hoping to be able to use the color picker and set a color per category that would populate across the site within the dashboard, so my clients could set the colors.”

Let’s take a look at what this solution gives you in the demo video.

Demo Video

Shows how you can use the color picker on every Edit Category screen to change the colors of different elements on single posts in that category. In this example, the color picker sets the colors for the entry title & entry meta however you can use it to set colors of any/all single post elements.

Installation Steps

There’s 2 steps :

# Step 1 – From the download folder, copy & paste the PHP code to the end of your child themes functions.php file.

Register or login to access the code in the download folder.

# Step 2 – Create a new field like this using ACF Pro :

Download Folder

Related Tutorials


Comments

3 responses to “Add Color Picker To Edit Category Screen To Set Color For Posts In Each Category”

  1. Tatiana M Avatar
    Tatiana M

    Hi Brad,
    How would I modify this code to work on the front page blog section? It’s already working beautifully on the archive pages, but changing this line
    if ( is_singular( ‘post’ ) || is_category() ) {
    to

    if( is_home() || is_singular( ‘post’ ) || is_category() || is_archive() ) {

    does work, BUT it adds this error to my portfolio page

    Warning: array_pop() expects parameter 1 to be array, boolean given in
    wp-content/themes/Hello Sassafras/functions.php on line 815

    Line 815 is

    $term = array_pop( $terms );

    Apologize in advance if it’s a silly mistake. I’ve been trying to wrap my head around PHP, but I’m seriously struggling with it.

    Thanks.
    -Tatiana
    website is http://mythandmagic.net

    1. If you don’t need this functionality on CPT archives, you can add this check

      [code]
      if ( is_post_type_archive( ‘portfolio’ ) )
      return;
      [/code]

      You’ll also need to add inline CSS to the PHP. Something like this :

      [code]
      .content .entry-header .entry-meta a,
      .content .entry-header .entry-meta,
      .content .entry-title a {
      color: %s;
      }
      [/code]

      And change the ACF Pro > Field Groups > Location settings.

      get_the_terms does return false sometimes so i’ll add a check and update the code in the download folder.

  2. Tatiana M Avatar
    Tatiana M

    Thank you! This is exactly what I needed. Appreciate your help!

Leave a Reply

Join 5000+ Followers

Get The Latest Free & Premium Tutorials Delivered The Second They’re Published.