do_action( ‘add_link’, int $link_id )

Fires after a link was added to the database.


ID of the link that was added.


do_action( 'add_link', $link_id );



User Contributed Notes

  1. Skip to note 2 content

    The add_link action hook is triggered in WordPress when a new link is added. You can use this hook to execute custom functions whenever a link is added to the WordPress database.

    // Add the action
    add_action( 'add_link', 'wpdocs_execute_on_add_link_event' );
    // Define the callback function
    function wpdocs_execute_on_add_link_event( $link_id ) {
        // Custom code to be executed when a new link is added
        // Use the $link_id parameter to perform operations related to the new link
    // Remove the action (if needed)
    remove_action( 'add_link', 'wpdocs_execute_on_add_link_event' );


    1. Ensure that your custom function is defined before you hook it using add_action.
    2. The priority and number of arguments in add_action and remove_action should match.
    3. You can add multiple functions to the same hook, and they will be executed in the order of their priority.

    By following the steps above, you can effectively use the add_link action hook to add custom functionality whenever a new link is added in WordPress.

You must log in before being able to contribute a note or feedback.