site_by_path_segments_count WordPress Filter Hook

The site_by_path_segments_count hook allows you to control how many segments (paths) are used to determine the current site. This is useful if you have a WordPress multisite installation with multiple sites sharing the same domain. By default, WordPress will use the first two segments of the path to determine the current site. However, if you have sites that share the same first two segments, you can use this hook to control how many segments are used. For example, if you have three sites sharing the same domain (example.com), you can use this hook to make WordPress use the third segment of the path to determine the current site. This would allow you to have the following URLs: example.com/site1 example.com/site2 example.com/site3 With this hook, you can also control how many segments are used for sub-sites. For example, if you have a WordPress multisite installation with multiple sites sharing the same domain, you can use this hook to make WordPress use the third segment of the path to determine the current sub-site. This would allow you to have the following URLs: example.com/site1/sub-site1 example.com/site1/sub-site2 example.com/site2/sub-site1 example.com/site2/sub-site2 This hook can be used in conjunction with the site_by_path hook to fine-tune how WordPress determines the current site.

apply_filters( 'site_by_path_segments_count', int|null $segments, string $domain, string $path ) #

Filters the number of path segments to consider when searching for a site.


Parameters

$segments

(int|null)The number of path segments to consider. WordPress by default looks at one path segment following the network path. The function default of null only makes sense when you know the requested path should match a site.

$domain

(string)The requested domain.

$path

(string)The requested path, in full.


Top ↑

Source

File: wp-includes/ms-load.php

View on Trac



Top ↑

Changelog

Changelog
VersionDescription
3.9.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.