title: Custom Meta Box for Wordpress add a checkbox that inserts a small bit of CSS
body: <p>I would like to add a simple meta box checkbox option to every post and page in a Wordpress site.  </p>
  
  <p>The text of the box: </p>
  
  <pre><code>'Check here to hide the slider featured text'
  </code></pre>
  
  <p>If the box is checked then it should insert the following CSS into the page:</p>
  
  <pre><code>.featured-text {  display: none !important;}
  </code></pre>
  
  <p>Thanks for any and all help with this.</p>
  
  <p>Here is what I'm working with:
  The metabox is inserting correctly and saving, but the css is not being added</p>
  
  <pre><code>// This section is working...
  
  // add meta checkbox to hide featured text on the slider
  
  add_action( 'add_meta_boxes', 'add_hide_slider_text' );
  function add_hide_slider_text()
  {
      add_meta_box( 'hide_slider_text_checkbox', 'Hide Slider Text', 'hide_slider_text_func', 'post', 'side', 'high' );
      add_meta_box( 'hide_slider_text_checkbox', 'Hide Slider Text', 'hide_slider_text_func', 'page', 'side', 'high' );
  }
  
  function hide_slider_text_func( $post )
  {
      $values = get_post_custom( $post-&gt;ID );
      $check = isset( $values['hide_slider_text_check'] ) ? esc_attr( $values['hide_slider_text_check'][0] ) : '';
      wp_nonce_field( 'my_hide_slider_text_nonce', 'hide_text_nonce' );
      ?&gt;
      &lt;p&gt;
          &lt;input type="checkbox" name="hide_slider_text_check" id="hide_slider_text_check" &lt;?php checked( $check, 'on' ); ?&gt; /&gt;
          &lt;label for="hide_slider_text_check"&gt;Hide slider text overlay?&lt;/label&gt;
      &lt;/p&gt;
      &lt;?php   
  }
  
  
  add_action( 'save_post', 'hide_text_option_save' );
  function hide_text_option_save( $post_id )
  {
      // Bail if we're doing an auto save
      if( defined( 'DOING_AUTOSAVE' ) &amp;&amp; DOING_AUTOSAVE ) return;
  
      // if our nonce isn't there, or we can't verify it, bail
      if( !isset( $_POST['hide_text_nonce'] ) || !wp_verify_nonce( $_POST['hide_text_nonce'], 'my_hide_slider_text_nonce' ) ) return;
  
      // if our current user can't edit this post, bail
      if( !current_user_can( 'edit_post' ) ) return;
  
      // now we can actually save the data
      $allowed = array( 
          'a' =&gt; array( // on allow a tags
              'href' =&gt; array() // and those anchords can only have href attribute
          )
      );
  
      // Save only if it's checked, or delete it if it's not
          if ( isset( $_POST['hide_slider_text_check'] ) &amp;&amp; $_POST['hide_slider_text_check'] ) {
                   add_post_meta( $post_id, 'hide_slider_text_check', 'on', true );
             } else {
               delete_post_meta( $post_id, 'hide_slider_text_check' );
  }
  }
  
  // this section isn't working at the moment
  
  // now we insert the new css if the box is checked
  
  
      if (get_post_meta($post-&gt;ID, 'hide_slider_text_check', true)) { 
  
      function my_styles_method() {
          wp_enqueue_style(
              'custom-style',
              get_template_directory_uri() . '/style.css' //if style.css is loaded then insert the css
          );
  
  
              $custom_css = "
  
              .featured-text {  display: none !important;}";
  
              wp_add_inline_style( 'custom-style', $custom_css );
      }
      add_action( 'wp_enqueue_scripts', 'my_styles_method' );
      }
  </code></pre>