Using Actions

Actions are a type of hook that are fired when an event happens. With actions, developers can tie into an action hook with the add_action() function. Likewise, they can remove an already hooked function with remove_action() . The first argument in both of these cases is the hook name and the second is the name of the function being added to or removed from the hook.

In Listing A.1, I demonstrate how to use the add_action() function to attach a function to a hook. This function uses the URL shortener service ( to create a shortened URL for a post when it is saved and adds it as a custom field called shorturl. You could use it for Twitter or any other service you wish to use a shortened URL form for.

Was this article helpful?

0 0

Post a comment