php-wordpressHow to use hooks in WordPress with an example?
Hooks are a way to modify or add functionality to WordPress without editing core files. They are used to add custom code to WordPress.
Example
add_action('init', 'my_custom_function');
function my_custom_function() {
// Do something
}
This code will execute the function my_custom_function
when the init
hook is called.
Code explanation
add_action
: This is a WordPress function that adds a custom function to a hook.init
: This is the name of the hook that the custom function will be added to.my_custom_function
: This is the name of the custom function that will be executed when theinit
hook is called.
Helpful links
More of Php Wordpress
- How to disable PHP warnings in WordPress?
- How to send an email using PHP in WordPress?
- How to get the current URL in WordPress using PHP?
- How to add a shortcode in WordPress?
- How to use get_header in WordPress using PHP?
- How to check the PHP version in WordPress?
- How to create a menu in WordPress using PHP?
- How to increase the upload limit in WordPress using PHP?
- How to redirect to another page in WordPress using PHP?
- How to create a snippet in WordPress using PHP?
See more codes...