If there are directories inside of the WordPress directory (popularly known as folders), identically worded permalinks don’t work, because the server checks their existence before it sends a request to WordPress.
This happens already with a default installation:
If we create a page with the permalink wp-admin/, that page will be unreachable. We should not change the order of server checks – existing files and directories over virtual – but we can prevent the creation of such permalinks.
There is a hook for that. Actually, even three. They have the beautiful names wp_unique_post_slug_is_bad_hierarchical_slug, wp_unique_post_slug_is_bad_flat_slug and wp_unique_post_slug_is_bad_attachment_slug. They are called when WordPress creates the slug for the permalink of a post or attachment.
We get two arguments on all three hooks: a boolean value (default:
FALSE) and the slug. If we return
TRUE and tell WordPress that this is a bad slug, it will search for another slug. During that, it adds ascending numbers to the original slug until it finds one that does not collide with other permalinks or our filter.
So our wp-admin/ would be changed to wp-admin-2/.
The filter function can be very simple:
* Do not allow slugs matching existing directories.
* @author MarketPress.com
* @see wp_unique_post_slug()
* @wp-hook wp_unique_post_slug_is_bad_hierarchical_slug
* @wp-hook wp_unique_post_slug_is_bad_flat_slug
* @wp-hook wp_unique_post_slug_is_bad_attachment_slug
* @param bool $bool Boolean value passed by the hook, default to false.
* @param string $slug
* @return bool TRUE if there is a directory with the same name.
function marketpress_prevent_directory_slugs( $bool, $slug )
if ( is_dir( ABSPATH . '/' . $slug ) )
The path has to be changed if WordPress is installed in a separate directory.
Because this code does not need a user interface and just works after enabling, we have put it into our repository Mini-Plugins on GitHub. You can download it here as a separate plugin: Protect directory URLs.
New Plugin: Slack Connector - Connect WordPress, WooCommerce and Slackby Michael Firnkes
Initially we merely wanted to optimize our own Slack-processes. With automated notifications from our MarkettPress shop, the blog and our forums. The resul ...Read more
Inpsyde is the first WordPress.com VIP partner in Germanyby Michael Firnkes
Automattic has given us the title of WordPress.com VIP Service Partner, the first in Germany, Austria and Switzerland. Worldwide, there are only eleven com ...Read more
Inpsyde is a WooExperts Gold Partner of WooCommerceby Michael Firnkes
A few weeks ago, Inpsyde GmbH with MarketPress became a certified WooExperts Gold Partner. This is confirmation from WooThemes of our agency’s know-h ...Read more
BackWPup Pro: Secure WordPress Backup with Google Driveby Michael Firnkes
The Pro version of our BackWPup plugin supports the backup of WordPress databases and files to Google Drive. But how do you set something like that up? And ...Read more