Skip to content

trepmal.com

  • Home
  • Plugins
  • Github
  • Me on WP.org
  • Donate

Categories

  • WordPress Bits (149)
  • Uncategorized (11)
  • Scripts (5)
  • Tidbits (5)
  • Fun (3)

Tags

  • wordpress (30)
  • administration (16)
  • plugin (9)
  • free download (8)
  • functions.php (8)

Year

  • 2018 (8)
  • 2016 (2)
  • 2015 (4)
  • 2014 (19)
  • 2013 (11)

Function: is_single

Use a Custom Field to Add to the

I needed a very simple way to custom styles or scripts to the <head>, and I didn’t really want to customize the theme.

add_action( 'wp_head', 'wp_head_custom_field' );
function wp_head_custom_field() {
    if ( is_single() ) {
        global $post;
        $html = get_post_meta( $post->ID, 'wp_head', true );
        echo $html;
    }
}

With this, I just needed to add my pre-formatted javascript or css to a custom field called ‘wp_head’ and it would then be added to the <head> just like I needed. I added the is_single() as a precaution.

Posted on March 30, 2011March 1, 2012Categories WordPress BitsTags custom fields1 Comment on Use a Custom Field to Add to the
Proudly powered by WordPress