Title: Automatically trigger bookmarklet
Last modified: August 19, 2016

---

# Automatically trigger bookmarklet

 *  [matrocka](https://wordpress.org/support/users/matrocka/)
 * (@matrocka)
 * [15 years, 10 months ago](https://wordpress.org/support/topic/automatically-trigger-bookmarklet/)
 * Hi All:
 * I have a baseball blog and a site (baseball-reference.com) has a bookmarklet 
   that when ran will automatically link baseball players to their corresponding
   baseball-reference page with stats. The bookmarklet works great with wordpress,
   but it’s a very manual process, is there any way to automatically trigger the
   bookmarklet to run after an article/page/etc is posted or updated?
 * The link to the playerlinker is here: [http://www.baseball-reference.com/linker/](http://www.baseball-reference.com/linker/)
 * Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [Darrell Schauss](https://wordpress.org/support/users/darrellonsite/)
 * (@darrellonsite)
 * [15 years, 10 months ago](https://wordpress.org/support/topic/automatically-trigger-bookmarklet/#post-1606121)
 * There are wordpress actions to make something happen duing a common wordpress
   event such as `edit_post`, `publish_post`, or `save_post`
 * [http://codex.wordpress.org/Plugin_API/Action_Reference#Post.2C_Page.2C_Attachment.2C_and_Category_Actions](http://codex.wordpress.org/Plugin_API/Action_Reference#Post.2C_Page.2C_Attachment.2C_and_Category_Actions)
 * In functions.php
 *     ```
       function your_function_name(){
       //do php stuff
   
       }
       add_action('publish_post','your_function_name');
       ```
   
 * [http://codex.wordpress.org/Plugin_API#Actions](http://codex.wordpress.org/Plugin_API#Actions)
 *  Thread Starter [matrocka](https://wordpress.org/support/users/matrocka/)
 * (@matrocka)
 * [15 years, 10 months ago](https://wordpress.org/support/topic/automatically-trigger-bookmarklet/#post-1606293)
 * How do I have the bookmarklet run on my post? Call the below javascript code 
   in PHP? would that work?
 * The source for the bookmarklet, for reference is:
 *     ```
       javascript:function%20sr_link()%20{var%20headID%20=%20document.getElementsByTagName(%22head%22)[0];var%20newScript%20=%20document.createElement(%27script%27);newScript.type%20=%20%27text/javascript%27;var%20random_param%20=%20Math.floor(Math.random()*1100);%20newScript.src%20=%20%27http://www.baseball-reference.com/linker/linker.js?rand=%27+random_param;%20headID.appendChild(newScript);}%20void(sr_link());
       ```
   
 *  Thread Starter [matrocka](https://wordpress.org/support/users/matrocka/)
 * (@matrocka)
 * [15 years, 10 months ago](https://wordpress.org/support/topic/automatically-trigger-bookmarklet/#post-1606320)
 * How would I go about calling a javascript function on add_action(‘publish_post’…)?

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Automatically trigger bookmarklet’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 3 replies
 * 2 participants
 * Last reply from: [matrocka](https://wordpress.org/support/users/matrocka/)
 * Last activity: [15 years, 10 months ago](https://wordpress.org/support/topic/automatically-trigger-bookmarklet/#post-1606320)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
