in PHP by (16.3k points)
0 like 0 dislike
111 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 (16.3k 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');
    

Please log in or register to answer this question.