Tự tạo một hook action trong wordpress

<?php

/* a custom action hook */

/*
 * 1. Create your own custom action hook named 'the_action_hook'
 *    with just a line of code. Yes, it's that simple.
 *
 *    The first argument to add_action() is your action hook name
 *    and the second argument is the name of the function that actually gets
 *    executed (that's 'callback function' in geek).
 *
 *    In this case you create an action hook named 'the_action_hook'
 *    and the callback function is 'the_action_callback'.
 */

add_action('the_action_hook', 'the_action_callback');

/*
 * 2. Declare the callback function. It prints a sentence.
 *    Note that there is no return value.
 */

function the_action_callback()
{
echo '<p>WordPress is nice!</p>';
}

/*
 * 3. When you call do_action() with your action hook name
 *    as the argument, all functions hooked to it with add_action()
 *    (see step 1. above) get are executed - in this case there is
 *    only one, the_action_callback(), but you can attach as many functions
 *    to your hook as you like.
 *
 *    In this step we wrap our do_action() in yet another
 *    function, the_action(). You can actually skip this step and just
 *    call do_action() from your code.
 */

function the_action()
{
do_action('the_action_hook');
}

?>
Các bài viết khác
Cùng lan toả
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
- Công việc chuyên môn là lập trình. - Thời gian làm việc đa số dùng internet cho nên cũng mong muốn chia sẻ những kiến thức và nhận định của mình cho mọi người về thế giới internet đầy rẫy tham sân si này. - Đã có vợ con. - Mọi liên hệ các bạn vui lòng email [email protected] hoặc [email protected]
Posts created 86

Related Posts

Begin typing your search term above and press enter to search. Press ESC to cancel.

Back To Top