get_subdirectory_reserved_names(): string[]

Retrieves a list of reserved site on a sub-directory Multisite installation.

Return

string[] Array of reserved names.

Source

function get_subdirectory_reserved_names() {
	$names = array(
		'page',
		'comments',
		'blog',
		'files',
		'feed',
		'wp-admin',
		'wp-content',
		'wp-includes',
		'wp-json',
		'embed',
	);

	/**
	 * Filters reserved site names on a sub-directory Multisite installation.
	 *
	 * @since 3.0.0
	 * @since 4.4.0 'wp-admin', 'wp-content', 'wp-includes', 'wp-json', and 'embed' were added
	 *              to the reserved names list.
	 *
	 * @param string[] $subdirectory_reserved_names Array of reserved names.
	 */
	return apply_filters( 'subdirectory_reserved_names', $names );
}

Hooks

apply_filters( ‘subdirectory_reserved_names’, string[] $subdirectory_reserved_names )

Filters reserved site names on a sub-directory Multisite installation.

Changelog

VersionDescription
4.4.0Introduced.

User Contributed Notes

  1. Skip to note 3 content

    Allow “/blog” in multsite network :

    function mod_subdirectory_reserved_names() {
        $names = array(
            'page', 'comments', 'files', 'feed', 'wp-admin',
            'wp-content', 'wp-includes', 'wp-json', 'embed'
        );
    }
    add_filter( "subdirectory_reserved_names", "mod_subdirectory_reserved_names");
  2. Skip to note 4 content

    Here is better solution to modify this list of reserved names. Solution by daniyalahmedk not working for 2 reasons:

    1. The function not returning anything. There is no return state in the function and WordPress get null as result of this function (not array with words).
    2. Function not accepting args. This means all other plugins/code changes will be replaced.
    /**
     * Modify reserved names for sites.
     *
     * @param $names array List of reserved names for sites.
     *
     * @return array Updated list of reserved names for sites.
     */
    function change_subdirectory_reserved_names( $names ) {
    	$position = array_search( 'blog', $names );
    
    	if( $position ) {
    		unset( $names[$position] );
    	}
    
    	return $names;
    }
    add_filter( 'subdirectory_reserved_names', 'change_subdirectory_reserved_names' );

You must log in before being able to contribute a note or feedback.