Using WordPress ‘dashboard_primary_link’ PHP filter

The dashboard_primary_link WordPress PHP filter allows you to modify the primary link URL for the ‘WordPress Events and News’ dashboard widget.

Usage

add_filter('dashboard_primary_link', 'my_custom_dashboard_primary_link');
function my_custom_dashboard_primary_link($link) {
// your custom code here
return $link;
}

Parameters

  • $link (string): The widget’s primary link URL.

More information

See WordPress Developer Resources: dashboard_primary_link

Examples

Change the primary link URL to your own custom URL.

add_filter('dashboard_primary_link', 'change_primary_link');
function change_primary_link($link) {
$link = 'https://www.example.com';
return $link;
}

Add UTM parameters to the primary link for tracking purposes.

add_filter('dashboard_primary_link', 'add_utm_parameters');
function add_utm_parameters($link) {
$utm_params = '?utm_source=dashboard&utm_medium=widget&utm_campaign=events_and_news';
$link .= $utm_params;
return $link;
}

Make the primary link open in a new tab by adding the target="_blank" attribute.

add_filter('dashboard_primary_link', 'open_link_in_new_tab', 10, 2);
function open_link_in_new_tab($link) {
$link = preg_replace('/(<a\s)/', '$1 target="_blank" ', $link);
return $link;
}

Redirect to an external event site

Redirect users to an external event site instead of the default link.

add_filter('dashboard_primary_link', 'redirect_to_external_event_site');
function redirect_to_external_event_site($link) {
$link = 'https://www.eventsite.com';
return $link;
}

Append a custom query string to the primary link.

add_filter('dashboard_primary_link', 'append_custom_query_string');
function append_custom_query_string($link) {
$custom_query = '&custom_variable=value';
$link .= $custom_query;
return $link;
}