3

How do you add a script on the footer of the post editor ? I'm adding a meta box under the post editor and I need to include a javascript before the closing body tag (on the footer)

How do I achieve this ?

The script is not needed on the front-end just on that meta_box (just on the post editor page)

user983248
  • 1,360
  • 3
  • 20
  • 31

1 Answers1

5

Hook into 'admin_footer-post-new.php' and 'admin_footer-post.php', check the global variable $post_type:

add_action( 'admin_footer-post-new.php', 'wpse_73692_script' );
add_action( 'admin_footer-post.php', 'wpse_73692_script' );

function wpse_73692_script()
{
    if ( 'post' !== $GLOBALS['post_type'] )
        return;

    ?>
<script>alert( '<?php echo $GLOBALS['post_type'];?>' );</script>
    <?php
}
fuxia
  • 107,219
  • 39
  • 255
  • 462