How and When to Use Actions and Filters

| Last Updated: | In: WordPress, WP Labs


WordPress allows developers to add their own code during the execution of a request by providing various hooks. These hooks come in the form of actions and filters:

Actions: WordPress invokes actions at certain points during the execution request and when certain events occur.

Filters: WordPress uses filters to modify text before adding it to the database and before displaying it on-screen.

action-filters

The number of actions and filters is quite large, so we can’t get into them all here, but let’s at least take a look at how they are used.

Here’s an example of how to use the admin_print_styles action, which allows you to add your own stylesheets to the WordPress admin pages:

And here’s how you would use the the_content filter to add a “Follow me on Twitter!” link to the bottom of every post:

Tags: ,


About: Prem Tiwari

Prem Tiwari is the founder of freewebmentor.com and is a professional developer who has vast experience in PHP and open source technologies. Apart from this, he is a blogger by hobby.


You may also like:

Get Free Access of 450+ Scripts

Don't worry you'll not be spammed!

Featured eBook

WordPress Security Guide

Free Guide: Learn how to implement security guideline in your WordPress site...

DOWNLOAD

Free WordPress Setup Service

Free WordPress Setup

Want to Setup WordPress Blog Setup? I will help you in the setup of your WordPress blog.

Click Here

Pincode Finder

pincode-finder tool

Online Pincode Finder

Best tool to locate post Office address and pincodes of all india...

SEARCH NOW