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 theinithook is called.
Helpful links
More of Php Wordpress
- How to get the current URL in WordPress using PHP?
- How to use get_header in WordPress using PHP?
- How to disable PHP warnings in WordPress?
- How to create a WordPress plugin using PHP?
- How to check the PHP version in WordPress?
- How to hide PHP warnings in WordPress?
- How to use the WordPress REST API with PHP?
- How to use body_class() in WordPress with PHP?
- How to increase the upload limit in WordPress using PHP?
- How to get the site URL in WordPress using PHP?
See more codes...