WP_Sitemaps_Registry::add_provider() WordPress Method

The WP_Sitemaps_Registry::add_provider() method allows a new sitemap provider to be registered with WordPress. A sitemap provider is a class that implements the WP_Sitemaps_Provider interface and is responsible for generating a sitemap for a given type of content. This method should be called from the 'init' action hook.

WP_Sitemaps_Registry::add_provider( string $name, WP_Sitemaps_Provider $provider ) #

Adds a new sitemap provider.


Parameters

$name

(string)(Required)Name of the sitemap provider.

$provider

(WP_Sitemaps_Provider)(Required)Instance of a WP_Sitemaps_Provider.


Top ↑

Return

(bool) Whether the provider was added successfully.


Top ↑

Source

File: wp-includes/sitemaps/class-wp-sitemaps-registry.php

	public function add_provider( $name, WP_Sitemaps_Provider $provider ) {
		if ( isset( $this->providers[ $name ] ) ) {
			return false;
		}

		/**
		 * Filters the sitemap provider before it is added.
		 *
		 * @since 5.5.0
		 *
		 * @param WP_Sitemaps_Provider $provider Instance of a WP_Sitemaps_Provider.
		 * @param string               $name     Name of the sitemap provider.
		 */
		$provider = apply_filters( 'wp_sitemaps_add_provider', $provider, $name );
		if ( ! $provider instanceof WP_Sitemaps_Provider ) {
			return false;
		}

		$this->providers[ $name ] = $provider;

		return true;
	}


Top ↑

Changelog

Changelog
VersionDescription
5.5.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.