• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

WP SITES

2785

Original Genesis & WooCommerce Tutorials & 6000+ Guaranteed Code

Snippets

  • Try Premium
  • Log in

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

  • Code Color Picker On Taxonomy Edit Screen To Style Post Meta On All Page Types Including Posts Page
  • Inline Style Post Category Links Using Color Picker
  • Code To Add Color Picker To Meta Box On Edit Post Screens
  • Add Color Picker To Edit Post Screen To Style Specific Single Post Elements

Custom Fields Taxonomy Terms

Reader Interactions

Comments

  1. Tatiana M says

    May 21, 2018 at 3:16 pm

    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

    Log in to Reply
    • Brad Dalton says

      May 21, 2018 at 3:48 pm

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

      if ( is_post_type_archive( 'portfolio' ) )
      	    return;

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

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

      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.

      Log in to Reply
  2. Tatiana M says

    March 23, 2018 at 8:50 pm

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

    Log in to Reply

Leave a Reply Cancel reply

You must be logged in to post a comment.

Primary Sidebar

Code written by Brad Dalton specialist for Genesis, WooCommerce & WordPress theme customization. Read More…

Advertise · WPEngine · Genesis · Log in

  • Access Problems
  • Account Details
  • Consulting
  • Tags
 

Loading Comments...
 

You must be logged in to post a comment.