Pippins Plugins
  • Email
  • Facebook
  • Feedburner
  • Github
  • Google
  • Twitter
  • Vimeo
  • Youtube
  • Rss
  • About
  • News
  • Join the Site
    • Member Benefits
    • Member Plugins
    • Email Notifications
  • Plugin Store
    • Affiliate Area
    • Checkout
  • Plugins
    • Plugin Portfolio
      • Plugin Portfolio – List View
    • Free
    • Premium
    • Member Plugins
    • Coding Standards
    • Get Plugin Support
  • Tutorials
    • Series
      • Plugin Development 101
      • Creating a User Follow System Plugin
      • Customizing Restrict Content Pro
      • Displaying Content with Easy Content Types
      • Writing Your First WordPress Plugins, Basic to Advanced
      • Working with Widgets
      • User Submitted Image Galleries
      • Plugin Thoughts
      • Integrating Stripe.com with WordPress
      • WordPress Rewrite API
    • Member Exclusive
      • Free Members
      • Subscriber Only
    • Difficulty
      • Beginner
      • Intermediate
      • Advanced
    • Action and Filter Hooks
    • Ajax
    • Custom Post Types
    • External APIs
    • Short Codes
    • Taxonomies
    • Video Tutorials
    • Widget Tutorials
    • WordPress Admin / Dashboard
    • Working with jQuery
    • WordPress Database
    • Writing Plugins
    • Tag Index
  • Reviews
  • Support Forum
  • Contact
    • Support the Site
    • Request Code Review
    • Plugin Support

Get the Name of the Current Action or Filter

Posted on March 19, 2012 by Pippin in Action and Filter Hooks, Intermediate, Quick Tips, Tutorials No Comments
Home» Tutorials » Action and Filter Hooks » Get the Name of the Current Action or Filter
Tweet
Love It - 2

After watching a Twitter discussion this morning (shown in the image below), Helen Hou-Sandi, a WordPress developer and core-committer mentioned a function I had never heard of that can be used for finding the name of the current action or filter hook. It is called current_filter() and is extremely useful. Check out the snippets below for examples.

Let’s say that you need to discover the name of the hook that is running, perhaps at a very specific time. The current_filter() function can be used for exactly that. While the examples below are very simple, they should illustrate the point well.

1
2
3
4
function pippin_show_current_filter() {
	echo 'Current action/filter: ' . current_filter(); exit;
}
add_action('template_redirect', 'pippin_show_current_filter');

When you load a page on your site, you will see:

Current action/filter: template_redirect
1
2
3
4
function pippin_show_current_filter() {
	echo 'Current action/filter: ' . current_filter(); exit;
}
add_action('pre_get_posts', 'pippin_show_current_filter');

Now when you load a page on your site, you will see:

Current action/filter: pre_get_posts
Tweet Follow @pippinsplugins
add_action, add_filter, current_filter

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

  • Login

Lost your password?

Please enter your username or e-mail address. You will receive a new password via e-mail.

  • Facebook Become a Fan Like

  • Twitter Subscribe on Twitter Follow

  • YouTube Follow my Videos Subscribe

  • RSS Feed Subscribe with RSS Subscribe

Easy Digital Downloads

Most Loved

  • Love It Pro for WordPress
  • Write a “Love It” Plugin with Ajax to Let Users Love Their Favorite Posts / Pages
  • Simple Notices Pro Plugin for WordPress
  • User Bookmarks for WordPress
  • Front End Registration and Login Forms Plugin

Similar Plugins and Posts

  • Plugin Development 101 – Intro to Actions
  • Plugin Development 101 – An Intro to Filters
  • Using pre_get_posts to Modify Queries for Meta Data and More
  • Introduction to the gettext Filter in WordPress
  • Let’s Talk Extensible Code

Latest Premium Content

  • Plugin Development 101 – Introduction to Adding Dashboard Menus
  • Plugin Development 101 – Intro to Loading Scripts and Styles
  • User Follow System – Part 5
  • Plugin Development 101 – Intro to Short Codes
  • Plugin Development 101 – Registering a Custom Post Type
  • Plugin Development 101 – Intro to Actions

Latest Tutorials

  • Submitting Your First Pull Request to a WordPress Plugin on Github (0)

    Github is an extremely popular tool for managing WordPress plugins, and one...

  • Plugin Development 101 – Introduction to Adding Dashboard Menus (1)

    Adding new menus, both top level and sub level, to the WordPress Dashboard is a really common task for plugins...

  • Plugin Development 101 – Intro to Loading Scripts and Styles (16)

    In this part of Plugin...

Enter your email to receive automated updates when new posts are published

Latest Tweets

  • @sunnyratilal awesome!
    May 18, 2013
  • @sfakuyi @chriscct7 it&#039;s really, really close
    May 18, 2013
  • @sfakuyi @chriscct7 yes it will
    May 18, 2013

Topics

shortcodes hook add_shortcode contextual help get_user_meta Sugar Event Calendar Rémi Corson meta box the_content Tom McFarlin register_setting wp_enqueue_script attachments mail chimp short codes Related posts plugin do_action login image authors forms attachment post types apply_filters bbpress recent posts comments taxonomies short code custom post type Ajax images gallery Stripe taxonomy jquery widgets users add_filter easy content types add_action widget restrict content pro easy digital downloads

Weekly Newsletter

Useful Links

  • Join the Site
  • Plugin Store
  • Affiliate Area
  • Tag Index
  • Support the Site
  • Suggest a Tutorial
  • Random Post
  • Contact

Monthly Archives

(c) 2011 Pippin's Plugins