Created
April 9, 2014 15:56
-
-
Save kadimi/10285884 to your computer and use it in GitHub Desktop.
Add Javascript in header for a post, a page or a custom type post, add your code in a custom field with the name "js"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Add JavaScript code to the head section | |
* | |
* Add a custom field with the name "js" and this plugin will | |
* add it content to the head section of the page/post wrapped | |
* correctly inside <script> tags. | |
*/ | |
add_action('wp_head', 'per_post_head_js'); | |
function per_post_head_js() { | |
if ( $post = get_post(get_query_var('p')) ) { | |
echo $js = get_post_meta( $post->ID, 'js', /* $single = */ true ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment