The iis7_supports_permalinks WordPress PHP function checks if IIS 7+ supports pretty permalinks.
Usage
To use the iis7_supports_permalinks function, simply call the function and it will return a boolean value indicating whether IIS 7+ supports pretty permalinks or not.
$pretty_permalinks_supported = iis7_supports_permalinks();
Parameters
This function has no parameters.
More information
See WordPress Developer Resources: iis7_supports_permalinks
Examples
Checking if pretty permalinks are supported
This example checks if pretty permalinks are supported and outputs a message accordingly.
$pretty_permalinks_supported = iis7_supports_permalinks();
if ($pretty_permalinks_supported) {
echo "IIS 7+ supports pretty permalinks.";
} else {
echo "IIS 7+ does not support pretty permalinks.";
}
Conditionally enabling pretty permalinks
This example enables pretty permalinks if supported by IIS 7+.
if (iis7_supports_permalinks()) {
// Enable pretty permalinks
update_option('permalink_structure', '/%postname%/');
} else {
// Fallback to default permalinks
update_option('permalink_structure', '');
}
Displaying a warning message in the admin panel
This example displays a warning message in the WordPress admin panel if pretty permalinks are not supported.
function check_pretty_permalinks_support() {
if (!iis7_supports_permalinks()) {
add_action('admin_notices', 'pretty_permalinks_warning');
}
}
function pretty_permalinks_warning() {
echo '<div class="notice notice-warning is-dismissible"><p><strong>Warning:</strong> IIS 7+ does not support pretty permalinks on this server.</p></div>';
}
add_action('admin_init', 'check_pretty_permalinks_support');
Redirecting users based on permalink support
This example redirects users to a custom error page if pretty permalinks are not supported.
function redirect_if_no_pretty_permalinks() {
if (!iis7_supports_permalinks()) {
wp_redirect('error-page.html');
exit;
}
}
add_action('template_redirect', 'redirect_if_no_pretty_permalinks');
Disabling a plugin if pretty permalinks are not supported
This example deactivates a specific plugin if pretty permalinks are not supported.
function deactivate_plugin_if_no_pretty_permalinks() {
if (!iis7_supports_permalinks()) {
deactivate_plugins('my-plugin/my-plugin.php');
}
}
add_action('admin_init', 'deactivate_plugin_if_no_pretty_permalinks');