Plugins, Themes, Wordpress

WordPress Hooks and Filters introduction

WordPress hooks are predefined functions that provide the facility of attaching your custom php code to wordpress. You can change or modify the default behavior wordpress using Hooks. Custom functions are applied into action hooks or filter hooks.

There are two types of wordpress Hooks.

1: Action hooks

2: Filter hooks

 

wordpress hooks

Action hooks are functions preformed when an event occure. for example if you want to perform an action to remove tool menu from wordpress dashboard , you can apply your custom function wtih predefined action admin_menu with add_action() function.

Example

add_action("admin_menu","my_custom_function"); 
function my_custom_function(){ 
remove_menu_page("tools.php");
}

 

filter hooks are used to modify the data and return the updated copy of original data. Filter hooks filter your data before displaying on front end or saving on database. for instance, if you want to modify the title of your blog posts, you can associate your function with the_title filter into add_filter() function.

Example

modify_post_title($title){ 
return strtoupper($title); 
} 
add_filter('the_title',"modify_post_title");

 

For more details you can visit wordpress codex

About Viren-Dra Yadav

Tech Enthlasis | Open Source Lover | Project Manager and DevOps Developer@EighteenPixels | Mad for Speed
View all posts by Viren-Dra Yadav →

Leave a Reply

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