Using WordPress ‘dashboard_primary_feed’ PHP filter

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

Usage

add_filter('dashboard_primary_feed', 'your_custom_function');
function your_custom_function($url) {
// your custom code here
return $url;
}

Parameters

  • $url (string) – The widget’s primary feed URL.

More information

See WordPress Developer Resources: dashboard_primary_feed

Examples

Change the primary feed URL

Change the primary feed URL to display news from a custom source.

add_filter('dashboard_primary_feed', 'change_primary_feed_url');
function change_primary_feed_url($url) {
$url = 'https://customsource.com/feed';
return $url;
}

Add a query parameter to the primary feed URL

Add a query parameter to filter the displayed news in the dashboard widget.

add_filter('dashboard_primary_feed', 'add_query_parameter_to_feed_url');
function add_query_parameter_to_feed_url($url) {
$url = $url . '?category=updates';
return $url;
}

Conditionally change the primary feed URL based on user role

Change the primary feed URL for a specific user role, such as ‘editor’.

add_filter('dashboard_primary_feed', 'conditionally_change_primary_feed_url');
function conditionally_change_primary_feed_url($url) {
if (current_user_can('editor')) {
$url = 'https://customsource.com/editor-feed';
}
return $url;
}

Use a secure (HTTPS) feed URL

Ensure the primary feed URL is using a secure connection.

add_filter('dashboard_primary_feed', 'use_secure_feed_url');
function use_secure_feed_url($url) {
$url = str_replace('http://', 'https://', $url);
return $url;
}

Remove the primary feed URL

Remove the primary feed URL to disable the ‘WordPress Events and News’ dashboard widget.

add_filter('dashboard_primary_feed', 'remove_primary_feed_url');
function remove_primary_feed_url($url) {
return '';
}