Sign up ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I came across this code and would like to use it in my project. It works fine, but the problem is, I need to change those colors in the array to instead pick transparent images from url since I am using it for background.

My first option was to find if someone could change the solid color to a gradient, but due to the complexity in my project, picking background images will be simpler.

/* Define the custom box */
add_action( 'add_meta_boxes', 'wpse_61041_add_custom_box' );

/* Do something with the data entered */
add_action( 'save_post', 'wpse_61041_save_postdata' );

/* Adds a box to the main column on the Post and Page edit screens */
function wpse_61041_add_custom_box() {
        'Title Color',

/* Prints the box content */
function wpse_61041_inner_custom_box($post)
    // Use nonce for verification
    wp_nonce_field( 'wpse_61041_wpse_61041_field_nonce', 'wpse_61041_noncename' );

    // Get saved value, if none exists, "default" is selected
    $saved = get_post_meta( $post->ID, 'title_color', true);
    if( !$saved )
        $saved = 'default';

    $fields = array(
        'red'       => __('Red', 'wpse'),
        'green'     => __('Green', 'wpse'),
        'blue'      => __('Blue', 'wpse'),
        'default'   => __('Default', 'wpse'),

    foreach($fields as $key => $label)
            '<input type="radio" name="title_color" value="%1$s" id="title_color[%1$s]" %3$s />'.
            '<label for="title_color[%1$s]"> %2$s ' .
            checked($saved, $key, false)

/* When the post is saved, saves our custom data */
function wpse_61041_save_postdata( $post_id ) 
      // verify if this is an auto save routine. 
      // If it is our form has not been submitted, so we dont want to do anything
      if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) 

      // verify this came from the our screen and with proper authorization,
      // because save_post can be triggered at other times
      if ( !wp_verify_nonce( $_POST['wpse_61041_noncename'], 'wpse_61041_wpse_61041_field_nonce' ) )

      if ( isset($_POST['title_color']) && $_POST['title_color'] != "" ){
            update_post_meta( $post_id, 'title_color', $_POST['title_color'] );

And the code link: Add a checkbox to post screen that adds a class to the title

share|improve this question
Welcome! Can you tell us what you have tired thus far to modify this existing code to meet your needs? –  Dan Mar 12 '14 at 20:13
Sure, i did create a plugin with it and used a short code in my content.php. With colors it works, but when i changed them to images, nothing words. What i did try was this by changing the field to $fields = array( gradient[0] => __('imageURL0.jpg', 'wpse'), gradient[1] => __('imageURL1.jpg', 'wpse'), gradient[2] => __('imageURL2.jpg', 'wpse'), gradient[3] => __('imageURL3.jpg', 'wpse'), ); but did not work,,,... –  Dani Mar 12 '14 at 20:19
Wish some could help-- I am new to wordpress hooks and not so much good in some stuffs in PHP –  Dani Mar 13 '14 at 0:21

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.