Support » Plugins » Hacks » Add JS when post is published

  • Resolved matoma16


    I am trying to add javascript when a post has been published so that it’s more noticable for my user but I can’t figure out what to use.
    I tryed with publish_post and save_post, but it doesn’t work unless I put die; at the end of the code.
    I’ve tryed so hard to stay out of the wordpress core code, and I really don’t want to have to because of this problem…
    here’s my code :

    function run_when_post_published($post_ID){
    			echo '<script type="text/javascript">
    add_action('publish_slider', 'run_when_post_published');

    Thanks for your help !

Viewing 2 replies - 1 through 2 (of 2 total)
  • You should probably use admin_notices instead of throwing a JS alert.

    Hi, thanks for your answer, I just looked at admin_notice.
    Can you please explain how I would go about showing it only when the post is published / updated ? Should I use the $_GET[‘message’] in the URL ?

    I need to add JS when the post is published to add things (message desapearing after 3 sec for example) and didn’t know how to add HTML without JS (before your answer). The alert in my code above is just the easiest way for me to see if a script is correctly linked or read 🙂

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Add JS when post is published’ is closed to new replies.