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.
Source
File: wp-includes/ms-load.php
Changelog
Version | Description |
---|---|
3.9.0 | Introduced. |