Title: Use color as PHP variable
Last modified: August 22, 2016

---

# Use color as PHP variable

 *  [itwd.ian](https://wordpress.org/support/users/itwdian/)
 * (@itwdian)
 * [11 years, 3 months ago](https://wordpress.org/support/topic/use-color-as-php-variable/)
 * Hi,
    I’m very happy with your plug-in. And am trying to integrate some of it’s
   features into a theme I’m working on. I’m using the following script to tweak
   certain colors chosen in customizer: [http://jaspreetchahal.org/how-to-lighten-or-darken-hex-or-rgb-color-in-php-and-javascript/](http://jaspreetchahal.org/how-to-lighten-or-darken-hex-or-rgb-color-in-php-and-javascript/)
 * My goal is to be able to pick a color for the navigation text and run that color
   tru this script to use a slightly darker shade as a hover effect.
    This is what
   I use for a color scheme
 *     ```
       $color_scheme = get_theme_mod('colorpalette_scheme');
       $color_scheme_darker = adjustColorLightenDarken($color_scheme,20);
       ```
   
 * Where $color_scheme can be used as standard and $color_scheme_darker as a hover
   effect.
 * My question is: is it possible to output just the chosen color of an element 
   into a PHP variable, which can then be used in the ‘adjustColorLightenDarken’
   script.
    As an example, here is the element I’ve added in my functions.php
 *     ```
       $options['eess_main-nav'] = array(
               'name'        => 'eess_main-nav',
               'title'       => 'Menu Text',
               'description' => 'Edit your menu fonts',
               'properties'  => array( 'selector' => '.main-nav a' ),
        );
       ```
   
 * Thanks in advance.
    Ian
 * [https://wordpress.org/plugins/easy-google-fonts/](https://wordpress.org/plugins/easy-google-fonts/)

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Plugin Author [Sunny Johal](https://wordpress.org/support/users/sunny_johal/)
 * (@sunny_johal)
 * [11 years, 3 months ago](https://wordpress.org/support/topic/use-color-as-php-variable/#post-5832627)
 * Hi Ian,
    Instead of doing all that additional work I would suggest that you just
   add an additional font control for the hover effect. E.g.
 *     ```
       $options['eess_main-nav-hover'] = array(
               'name'        => 'eess_main-nav-hover',
               'title'       => 'Menu Text Hover',
               'description' => 'Edit your menu fonts',
               'properties'  => array( 'selector' => '.main-nav a:hover' ),
        );
       ```
   
 * Let me know your thoughts. Cheers
    Sunny
 *  Thread Starter [itwd.ian](https://wordpress.org/support/users/itwdian/)
 * (@itwdian)
 * [11 years, 3 months ago](https://wordpress.org/support/topic/use-color-as-php-variable/#post-5832630)
 * Thanks for the quick reply.
    I understand that that is an option, and I’ve used
   it in the past. This time I’m trying to simplify things for the end user. Giving
   them as few (sometimes confusing) options with the best results. If that means
   more coding on my part so be it.
 *  Plugin Author [Sunny Johal](https://wordpress.org/support/users/sunny_johal/)
 * (@sunny_johal)
 * [11 years, 3 months ago](https://wordpress.org/support/topic/use-color-as-php-variable/#post-5832649)
 * Hi Ian,
    Support on this issue is going to be quite limited (mainly due to limitations
   of my free time). But you would have to:
    - Hook into the `'wp_head'` action and provide a function that:
 *  - Loops through the controls array.
    - Checks if the name of the control matches the one you want to output the hover
      effect for.
    - Store that variable by accessing the `'font_color'` attribute of the control
      and making sure the user has set a value.
    - Look at the `output_styles()` function in the includes/class-egf-frontend.
      php file for an example of looping through the controls.
 *  - You would also have to write your own custom javascript to support the live
      previewer and enqueue it on the page as necessary. Look at the assets/js/customize-
      preview.js file to see how I have implemented the live preview for each control
      dynamically.
 * Again, providing custom implementation support like that is beyond any support
   I’d provide in these forums but let me know how you get on. Cheers,
    Sunny

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Use color as PHP variable’ is closed to new replies.

 * ![](https://ps.w.org/easy-google-fonts/assets/icon-256x256.png?rev=2562365)
 * [Easy Google Fonts](https://wordpress.org/plugins/easy-google-fonts/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/easy-google-fonts/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/easy-google-fonts/)
 * [Active Topics](https://wordpress.org/support/plugin/easy-google-fonts/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/easy-google-fonts/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/easy-google-fonts/reviews/)

 * 3 replies
 * 2 participants
 * Last reply from: [Sunny Johal](https://wordpress.org/support/users/sunny_johal/)
 * Last activity: [11 years, 3 months ago](https://wordpress.org/support/topic/use-color-as-php-variable/#post-5832649)
 * Status: not resolved