in PHP by (14.2k points)
0 like 0 dislike
54 views

How I can to add custom hook for own theme in WordPress CMS?


wordpress add hook to theme

1 Answer

0 like 0 dislike
by (14.2k points)

You can do it in 3 simply steps:

  1. Add hook function in theme "functions.php" file and in it call hook action:
    function custom_hook_fnc() {
    	do_action('custom_hook_title');
    }
    
  2. Add hook function in needed place of theme template:
    <?php custom_hook_fnc(); ?>
    
  3. Add custom function in plugin or child theme and tell action for call it using hooks:
    function display_something() {
    	echo '<p>Test display custom hook text.</p>';
    }
    add_action('custom_hook_title', 'display_something');
    

Your answer

Try to answer the question as detailed as possible.
Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.