Skip to content

Instantly share code, notes, and snippets.

  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save stevegrunwell/3111555 to your computer and use it in GitHub Desktop.
Hooked on WordPress Actions and Filters - WordCamp Columbus 2012

Hooked on WordPress Actions and Filters

July 14, 2012

Instructor: John Dillick (@johndillick)

Slides: http://www.slideshare.net/johndillick/actions-filters

What are actions?

Points within the code that allow developers to hook into the execution chain ("give you and opportunity to do something too")

WordPress Codex

Examples of action hooks

// Basic

// Pass variables into the action

Adding an action

// Object-oriented

Remember that action hooks have priority levels - those with a higher priority will be executed first.

Removing actions

remove_action( $tag, $callback, $priority, $args )

remove_all_actions( $tag, $priority )

Common actions

  • init
  • admin_init
  • wp_head
  • wp_footer
  • admin_head
  • admin_footer

Complete list: http://codex.wordpress.org/Plugin_API/Action_Reference

Filters

Filter content then return the filtered result

WordPress Codex

Syntax

Example

In 2010, WordPress added the capital_P_dangit callback to the_content, the_title, comment_text so that "Wordpress" would always be camel-cased as "WordPress"

Removing filters

remove_filter( $tag, $callback, $priority, $args )

remove_all_filters( $tag, $priority )

Common filters

  • the_content
  • the_excerpt
  • the_title

(Semi-)complete list: http://codex.wordpress.org/Plugin_API/Filter_Reference

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment