• Follow us on Twitter
  • Join our Facebook Group
  • Join me on Google Plus
  • Add me on Linkedin
  • RSS
Welcome to Ontwerps close

  • Home
  • Over
  • Diensten
  • Portfolio
  • Blog
  • Contact

Blog

WordPress – Add Javascript to a Single Post

0 Comments/ in Blog, Wordpress-CMS / by ontwerps
juli 7, 2010 Add the following immediately before the call to wp_head:
/* If the post has the 'javascript' custom field, load a script
	 * The script to load is based on the value of the 'javascript' field
	 */
	if ( is_single() && get_post_meta($post->ID, 'javascript', true) ) {
		$script = get_post_meta($post->ID, 'javascript', true);
		$script_path = get_bloginfo('template_url') . '/js/' . $script . '.js';
		wp_enqueue_script( $script, $script_path );
	}
For example, if you want to use a javascript called custom.js on your post, you’ll have to create a folder in your theme directory called js and put your jacascript there (for me the path would be www.domainname.com/wp-content/themes/yourtheme/js). Then add a Custom Field to your post named javascript with the value custom.

No related posts.

← WordPress – Add CSS to a Single Post
Another Drop Shadow →
Comments

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Geef een reactie Reactie annuleren

Je e-mailadres wordt niet gepubliceerd. Verplichte velden zijn gemarkeerd met *

*

*

De volgende HTML tags en attributen zijn toegestaan: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Categorieën

Tags

blackberry borders branding centos chrome cms color CSS css3 cycling debug font glyphs gradients hover HTML-HTML5 image import invoice iphone joomla jquery linux magento osx pattern photoshop scroll sql table Template textures twitter vcard Wordpress-CMS
© Copyright2012 - Design by ontwerps