What types of hooks are used in wordpress?

What types of hooks are used in wordpress?

Team Leader Asked on February 11, 2017 in WORDPRESS.
Add Comment
1 Answer(s)

    In WordPress there are two types of hooks – Action Hooks and Filter Hooks.
    1. Action Hooks:
    Action hooks allow you to add additional code to the WordPress core or theme so that you can achieve some new functionality or new level of customizations.

    Create a function in your theme’s functions.php file and hook it on using the add_action() function.

    add_action( 'wp_head', 'aviance_actionhook_demo' );
    function aviance_actionhook_demo () {
    echo '<meta name="keywords" content="wordpress action hooks and filter hooks introduction" />' . "
    } // End aviance_actionhook_demo()

    2. Filter Hooks:

    Filter hooks are used to manipulate output. An example of this would be to add a line or text to the end of the content of each of your blog posts. Filter hooks can also be used for truncating text, changing formatting of the content.

    add_filter( ‘wp_title’, ‘Add_sitename_to_wptitle’, 10, 2 );
    Add_sitename_to_wptitle( $title, $sep ) {
    /* Get website name. */
    $name = get_bloginfo( ‘name’ );
    /* Append website name to $title. */
    $title .= $sep . ‘ ‘ . $name;
    /* Return the title. */
    return $title;
    Team Leader Answered on February 25, 2017.
    Add Comment

    Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.