Extend LinkCentral with Hooks
Developers can extend LinkCentral functionality using hooks. The following hooks are available:
Link Clicks & Redirect
linkcentral_link_clicked – Action hook fired when a LinkCentral link is clicked. No further validations have happened at this point, such as a check if the link is a draft, set as private, scheduled for the future, or password protected.
The hook passes:
- The link ID
- The link slug
- The full link post object
/**
* @param int $link_id The ID of the clicked link
* @param string $slug The slug of the clicked link
* @param WP_Post $link The full link post object
*/
add_action('linkcentral_link_clicked', function($link_id, $slug, $link) {
// Access post data from the link object
$title = $link->post_title;
$created_date = $link->post_date;
// Perform custom operations with the link data
my_custom_function($link_id, $title);
}, 10, 3);
linkcentral_before_redirect – Action hook that is triggered right before a valid link is redirected. All checks have passed. The hook passes:
- The link ID
- The link slug
- The final destination URL
- The redirection type
- The full link post object
/**
* @param int $link_id The ID of the link
* @param string $slug The slug of the link
* @param string $destination_url The final destination URL
* @param int $redirection_type The HTTP redirection code (301, 302, 307)
* @param WP_Post $link The full link post object
*/
add_action('linkcentral_valid_link_redirect', function($link_id, $slug, $destination_url, $redirection_type, $link) {
// Send data to an external analytics system
my_analytics_service::track_outbound_link([
'link_id' => $link_id,
'slug' => $slug,
'destination' => $destination_url,
'user_id' => get_current_user_id()
]);
}, 10, 5);