The customize_allowed_urls WordPress PHP filter modifies the list of URLs allowed to be clicked and followed in the Customizer preview.
Usage
add_filter('customize_allowed_urls', 'my_custom_allowed_urls'); function my_custom_allowed_urls($allowed_urls) { // your custom code here return $allowed_urls; }
Parameters
$allowed_urls
(string[]): An array of allowed URLs.
More information
See WordPress Developer Resources: customize_allowed_urls
Examples
Add a new URL to the allowed list
Add https://www.example.com
to the list of allowed URLs in the Customizer preview.
add_filter('customize_allowed_urls', 'add_example_url'); function add_example_url($allowed_urls) { $allowed_urls[] = 'https://www.example.com'; return $allowed_urls; }
Allow all URLs from a specific domain
Allow all URLs from the domain example.com
to be clicked and followed in the Customizer preview.
add_filter('customize_allowed_urls', 'allow_example_domain'); function allow_example_domain($allowed_urls) { $allowed_urls[] = 'https://example.com/*'; return $allowed_urls; }
Remove a specific URL from the allowed list
Remove https://www.example.com
from the list of allowed URLs in the Customizer preview.
add_filter('customize_allowed_urls', 'remove_example_url'); function remove_example_url($allowed_urls) { $key = array_search('https://www.example.com', $allowed_urls); if ($key !== false) { unset($allowed_urls[$key]); } return $allowed_urls; }
Allow all URLs except a specific domain
Allow all URLs except those from the domain example.com
to be clicked and followed in the Customizer preview.
add_filter('customize_allowed_urls', 'disallow_example_domain'); function disallow_example_domain($allowed_urls) { $allowed_urls = array_filter($allowed_urls, function($url) { return !preg_match('/^https?:\/\/example\.com\//', $url); }); return $allowed_urls; }
Clear the allowed URLs list
Remove all URLs from the allowed list in the Customizer preview.
add_filter('customize_allowed_urls', 'clear_allowed_urls'); function clear_allowed_urls($allowed_urls) { return array(); }