Hooks are a way for one piece of code to interact/modify another piece of code. They make up the foundation for how plugins and themes interact with WordPress Core, but they’re also used extensively by Core itself.
There are two types of hooks: Actions and Filters. To use either, you need to write a custom function known as a Callback, and then register it with WordPress hook for a specific Action or Filter.
Below is an example of a hook used with a filter in WordPress:
1 2 3 4 5 6 7 8 9 10 11 | function wpb_custom_excerpt( $output ) { if ( has_excerpt() && ! is_attachment() ) { $output .= wpb_continue_reading_link(); } return $output; } add_filter( 'get_the_excerpt', 'wpb_custom_excerpt' ); |
Following example demonstrate how to register a Custom Menu in the Admin.
1 2 3 4 5 | function register_my_custom_menu_page() { add_menu_page( 'custom menu title', 'custom menu', 'manage_options', 'myplugin/myplugin-admin.php', '', 'dashicons-admin-site', 6 ); } add_action( 'admin_menu', 'register_my_custom_menu_page' ); |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.