GT Link Manager exposes a set of WordPress actions and filters that let you extend its behavior without modifying plugin files. This chapter documents each hook, its parameters, and common use cases.
Actions
gtlm_activated
Fires immediately after the plugin activation routine completes. No parameters.
Use this to run one-time setup in your own plugin or theme after GT Link Manager tables and rules are in place.
add_action( 'gtlm_activated', function() {
// Seed default links, log the event, etc.
} );
gtlm_after_save
Fires after a link is created or updated via the admin form.
Parameters:
$link_id — int. The ID of the saved link.
$insert_data — array. The normalized data that was written to the database.
Use this to sync links to an external system, invalidate a custom cache, or send a notification.
add_action( 'gtlm_after_save', function( $link_id, $insert_data ) {
// $insert_data has keys: name, slug, url, redirect_type, rel, noindex,
// is_active, category_id, tags, notes, link_mode, regex_replacement, priority
}, 10, 2 );
gtlm_after_delete
Fires after a link is permanently deleted.
Parameters:
$link_id — int. The ID of the deleted link.
$link — array. The full link record as it existed before deletion.
add_action( 'gtlm_after_delete', function( $link_id, $link ) {
// Clean up any external references to $link['slug']
}, 10, 2 );
gtlm_before_redirect
Fires just before the HTTP redirect response is sent. This is the correct place to add click tracking, logging, or analytics.
Parameters:
$link — array. The full link record from the database, including link_mode, regex_replacement, and priority fields.
$target_url — string. The destination URL the visitor is being redirected to (after any filter modifications and regex substitution).
$status — int. The HTTP status code (301, 302, or 307).
$headers — array. All response headers about to be sent.
add_action( 'gtlm_before_redirect', function( $link, $target_url, $status, $headers ) {
// Log to your analytics service
my_analytics_track( [
'event' => 'link_click',
'slug' => $link['slug'],
'mode' => $link['link_mode'],
'url' => $target_url,
'status' => $status,
] );
}, 10, 4 );
gtlm_settings_saved
Fires after settings are saved via the admin settings form.
Parameters:
$settings — array. The new settings values that were saved, including enable_advanced_redirects.
add_action( 'gtlm_settings_saved', function( $settings ) {
// React to setting changes
} );
Filters
gtlm_settings
Filters the plugin settings after they’re loaded from the database. This lets you programmatically override any setting without touching wp_options.
Parameters:
$settings — array. The settings array with keys base_prefix, default_redirect_type, default_rel, default_noindex, enable_advanced_redirects.
add_filter( 'gtlm_settings', function( $settings ) {
$settings['base_prefix'] = 'out';
$settings['enable_advanced_redirects'] = 1;
return $settings;
} );
gtlm_prefix
Filters just the base prefix value at the point it’s used by the redirect handler and rewrite rule registration. Overriding here is more targeted than using gtlm_settings.
Parameters:
$prefix — string. The current base prefix.
add_filter( 'gtlm_prefix', function( $prefix ) {
return 'ref';
} );
gtlm_cache_ttl
Filters the object cache TTL for slug lookups. The default is 0, which means the entry is cached without an expiry. Set an integer value in seconds to use a time-based expiry.
Parameters:
$ttl — int. Current TTL in seconds.
$slug — string. The slug being looked up (or direct:{path} for direct links, or regex_rules for regex rule sets).
$link — array|null. The link record if found, null if not.
add_filter( 'gtlm_cache_ttl', function( $ttl, $slug, $link ) {
return 3600; // Cache for one hour
}, 10, 3 );
gtlm_redirect_url
Filters the destination URL before the redirect is issued. The link has already been found in the database at this point. For regex links, capture group substitution has already been applied.
Parameters:
$url — string. The destination URL (after regex substitution, if applicable).
$link — array. The full link record.
$slug — string. The slug from the request (for standard links) or the matched path (for direct/regex links).
add_filter( 'gtlm_redirect_url', function( $url, $link, $slug ) {
// Append a UTM parameter
return add_query_arg( 'utm_source', 'yoursite', $url );
}, 10, 3 );
gtlm_redirect_code
Filters the HTTP status code used for the redirect.
Parameters:
$status — int. The redirect status code (301, 302, or 307).
$link — array. The full link record.
$slug — string. The slug or matched path from the request.
add_filter( 'gtlm_redirect_code', function( $status, $link, $slug ) {
// Force all redirects to 302 for logged-in users
if ( is_user_logged_in() ) {
return 302;
}
return $status;
}, 10, 3 );
gtlm_rel_attributes
Filters the rel attribute values for the redirect response’s Link header.
Parameters:
$rel_values — array. An array of rel strings (e.g., ['nofollow', 'sponsored']).
$link — array. The full link record.
$slug — string. The slug or matched path from the request.
add_filter( 'gtlm_rel_attributes', function( $rel_values, $link, $slug ) {
// Ensure nofollow is always present
if ( ! in_array( 'nofollow', $rel_values, true ) ) {
$rel_values[] = 'nofollow';
}
return $rel_values;
}, 10, 3 );
gtlm_headers
Filters the full array of response headers before they’re sent. This is the most powerful redirect filter — you can add, remove, or modify any header.
Parameters:
$headers — array. Associative array of header name to header value.
$link — array. The full link record.
$slug — string. The slug or matched path from the request.
add_filter( 'gtlm_headers', function( $headers, $link, $slug ) {
$headers['Referrer-Policy'] = 'no-referrer';
return $headers;
}, 10, 3 );
gtlm_capabilities
Filters the capability required to access specific plugin contexts. Use this to restrict or expand access.
Parameters:
$capability — string. The current capability string (e.g., edit_posts or manage_options).
$context — string. The context requesting the capability. Values include view_links, edit_links, delete_links, manage_settings, rest_api, import_export.
add_filter( 'gtlm_capabilities', function( $capability, $context ) {
// Only admins can manage links
if ( in_array( $context, [ 'edit_links', 'delete_links' ], true ) ) {
return 'manage_options';
}
return $capability;
}, 10, 2 );
gtlm_link_columns
Filters the columns displayed in the All Links admin list table. Useful for adding or removing columns.
Parameters:
$columns — array. Associative array of column ID to column label.
add_filter( 'gtlm_link_columns', function( $columns ) {
// Remove the tags column
unset( $columns['tags'] );
return $columns;
} );