Hook References

Filter Hooks

bwp_gxs_freq

Filter the change frequency of a sitemap entry.

Example

add_filter('bwp_gxs_freq', 'bwp_gxs_freq');
function bwp_gxs_freq($frequency, $item)
{
    // your codes
    return $frequency;
}

Parameters

string $frequency

The change frequency to filter.

object|null $item

The current item object or null

Expected Returned Value

string

Should be one of the change frequencies listed here: http://www.sitemaps.org/protocol.html#changefreqdef

bwp_gxs_priority_score

Filter the priority of a sitemap entry.

Example

add_filter('bwp_gxs_priority_score', 'bwp_gxs_priority_score');
function bwp_gxs_priority_score($score, $item, $frequency)
{
    // your codes
    return $score;
}

Parameters

float $score

The score to filter.

array $item

The current item.

string $frequency

The current change frequency.

Expected Returned Value

integer

See http://www.sitemaps.org/protocol.html#prioritydef

bwp_gxs_news_keyword_map

Filter to map your categories in your language to Google News's suggested categories in English.

See https://support.google.com/news/publisher/answer/116037 for more info.

Example

// add to theme's functions.php
add_filter('bwp_gxs_news_keyword_map', 'bwp_gxs_news_keyword_map');
function bwp_gxs_news_keyword_map($keywords_map)
{
	return array(
		'エンターテインメント' => 'entertainment',
		'ビジネス'=> 'business'
	);
}

Parameters

array $keywords_map

List of mappings.

Expected Returned Value

array

An array with your local keywords as keys and their English counterparts as values.

bwp_gxs_module_mapping

Filter to map a sitemap module to another sitemap module.

When a module is mapped to another module, the generation of the mapped module will be handled by the target module.

Example

add_filter('bwp_gxs_module_mapping', 'bwp_gxs_module_mapping');
function bwp_gxs_module_mapping($mappings)
{
    // your codes
    return $mappings;
}

Parameters

array $mappings

List of mappings.

Expected Returned Value

array

An array with the module to be mapped as key and the mapped-to module as value. Example:

return array(
    'post_format => 'post_tag'
);

bwp_gxs_rewrite_rules

Filter the rewrite rules used by this plugin.

This is mostly useful when you want to add a custom sitemap or a sitemap index. See http://betterwp.net/wordpress-plugins/google-xml-sitemaps/#create-another-sitemap-index for an example.

Example

add_filter('bwp_gxs_rewrite_rules', 'bwp_gxs_rewrite_rules');
function bwp_gxs_rewrite_rules($rules)
{
    // your codes
    return $rules;
}

Parameters

array $rules

List of rules to filter.

bwp_gxs_cache_dir

Filter sitemap cache directory.

Example

add_filter('bwp_gxs_cache_dir', 'bwp_gxs_cache_dir');
function bwp_gxs_cache_dir($cache_dir)
{
    // your codes
    return $cache_dir;
}

Parameters

string $cache_dir

Expected Returned Value

string

A full path to a custom cache directory.

bwp_gxs_query_var_non_perma

Filter the query variable to use when not using pretty permalink.

Example

add_filter('bwp_gxs_query_var_non_perma', 'bwp_gxs_query_var_non_perma');
function bwp_gxs_query_var_non_perma($query_variable)
{
    // your codes
    return $query_variable;
}

Parameters

string $query_variable

Name of the query variable to use. Default to 'bwpsitemap'.

bwp_gxs_xslt

Filter the XSLT stylesheet used to "prettify" sitemaps.

Example

add_filter('bwp_gxs_xslt', 'bwp_gxs_xslt');
function bwp_gxs_xslt($stylesheet)
{
    // your codes
    return $stylesheet;
}

Parameters

string $stylesheet

Expected Returned Value

string

A full URL to the stylesheet. Remember to use the same host as your sitemaps'. Also make sure that you have a stylesheet for the sitemap index in the same location (with the suffix "index" added).

bwp_gxs_news_name

Filter the name used for the Google News Sitemap.

Example

add_filter('bwp_gxs_news_name', 'bwp_gxs_news_name');
function bwp_gxs_news_name($news_name)
{
    // your codes
    return $news_name;
}

Parameters

string $news_name

The name to filter.

bwp_gxs_freq_site

Filter the frequency of a website in the Site Address sitemap.

Example

add_filter('bwp_gxs_freq_site', 'bwp_gxs_freq_site');
function bwp_gxs_freq_site($frequency, $blog_id)
{
    // your codes
    return $frequency;
}

Parameters

string $frequency

The change frequency to filter.

integer $blog_id

The current blog id.

Expected Returned Value

string

Should be one of the change frequencies listed here: http://www.sitemaps.org/protocol.html#changefreqdef

bwp_gxs_excluded_posts

Filter posts that are added to a post-based sitemaps.

Example

add_filter('bwp_gxs_excluded_posts', 'bwp_gxs_exclude_posts', 10, 2);
function bwp_gxs_exclude_posts($post_ids, $post_type)
{
	// $post_type let you easily exclude posts from specific post types
	switch ($post_type)
	{
		case 'post': return array(1,2,3,4); break; // the default post type
		case 'movie': return array(5,6,7,8); break; // the 'movie' post type
	}

	return array();
}

Parameters

array $post_ids

Post IDs to exclude.

string $post_type

The post type being processed. See http://codex.wordpress.org/Function_Reference/register_post_type for more info.

bwp_gxs_post_where

Filter the WHERE part of a post module's query.

Example

// add to theme's functions.php
add_filter('bwp_gxs_post_where', 'bwp_gxs_post_where', 10, 2);
function bwp_gxs_post_where($where, $post_type)
{
	// $post_type let you easily exclude posts from specific post types
	switch ($post_type)
	{
		case 'post': return ' AND p.ID NOT IN (1,2,3,4) '; break; // the default post type
		case 'movie': return ' AND p.ID NOT IN (5,6,7,8) '; break; // the 'movie' post type
	}

	return '';
}

Parameters

string $where

The WHERE part.

string $post_type

The current post type.

Expected Returned Value

string

Make sure you use p as the table alias, for e.g. WHERE p.post_password = 'password'. The wposts alias is kept for backward-compatibility purpose only and can be removed without notice.

bwp_gxs_external_pages

Filter the pages that are added to the external-page sitemap.

Example

// add to theme's functions.php
add_filter('bwp_gxs_external_pages', 'bwp_gxs_external_pages');
function bwp_gxs_external_pages($pages)
{
	return array(
		array('location' => home_url('link-to-page.html'), 'lastmod' => '06/02/2011', 'frequency' => 'auto', 'priority' => '1.0'),
		array('location' => home_url('another-page.html'), 'lastmod' => '05/02/2011', 'frequency' => 'auto', 'priority' => '0.8')
	);
}

Parameters

array $pages

External pages to add.

Expected Returned Value

array

List of external pages with following fields:

bwp_gxs_sitemap_lastmod

Filter last modified datetime of a sitemap entry in a sitemap index.

Example

add_filter('bwp_gxs_sitemap_lastmod', 'bwp_gxs_sitemap_lastmod');
function bwp_gxs_sitemap_lastmod($formatted_lastmod, $lastmod, $item, $part)
{
    // your codes
    return $formatted_lastmod;
}

Parameters

string $formatted_lastmod

Formatted last modified datetime, example: 2015-12-27 12:00:00.

integer $lastmod

Last modified datetime in Unix Timestamp.

array $item

The sitemap item being built.

integer $part

Current sitemap part (when splitting post-based sitemaps).

Expected Returned Value

string

A valid datetime, for a list of supported datetime format, see http://php.net/manual/en/datetime.formats.php

bwp_gxs_external_sitemaps

Filter external sitemaps to be added in the sitemap index.

This filter hook allows you to add sitemaps that are not handled by BWP GXS to the sitemap index.

Example

add_filter('bwp_gxs_external_sitemaps', 'bwp_gxs_external_sitemaps');
function bwp_gxs_external_sitemaps($external_sitemaps)
{
    // your codes
    return $external_sitemaps;
}

Parameters

array $external_sitemaps

Sitemaps to add.

bwp_gxs_excluded_terms

Filter terms that are added to a taxonomy-based sitemaps.

Example

// add to theme's functions.php
add_filter('bwp_gxs_excluded_terms', 'bwp_gxs_exclude_terms', 10, 2);
function bwp_gxs_exclude_terms($term_ids, $taxonomy)
{
    // $taxonomy let you easily exclude terms from specific taxonomies
    switch ($taxonomy)
    {
        case 'category': return array(1,2,3,4); break;
        case 'post_tag': return array(5,6,7,8); break;
    }

    return array();
}

Parameters

array $term_ids

Term IDs to exclude.

string $taxonomy

The current taxonomy. See http://codex.wordpress.org/Function_Reference/register_taxonomy for more info.

bwp_gxs_excluded_term_slugs

Filter terms that are added to a taxonomy-based sitemaps using their slugs.

Example

// add to theme's functions.php
add_filter('bwp_gxs_excluded_term_slugs', 'bwp_gxs_excluded_term_slugs', 10, 2);
function bwp_gxs_excluded_term_slugs($term_slugs, $taxonomy)
{
    // $taxonomy let you easily exclude terms from specific taxonomies
    switch ($taxonomy)
    {
        case 'category': return array('cat-slug1', 'cat-slug2'); break;
        case 'post_tag': return array('tag-slug1', 'tag-slug2'); break;
    }

    return array();
}

Parameters

array $term_slugs

Term slugs to exclude, e.g. 'tag1', 'category-2' etc.

string $taxonomy

The current taxonomy.

Action Hooks

bwp_gxs_modules_built

Fire after all default modules are defined.

You can use this action hook to add or remove sitemap modules dynamically.

For a complete example, see http://betterwp.net/wordpress-plugins/google-xml-sitemaps/#modules-api

Example

// add to theme's functions.php
add_action('bwp_gxs_modules_built', 'bwp_gxs_modules_built');
function bwp_gxs_modules_built($modules, $post_types, $taxonomies)
{
	// need to import plugin instance
	global $bwp_gxs;

	// add "movie" post sitemap
	$bwp_gxs->add_module('post', 'movie');

	// remove "private" post sitemap
	$bwp_gxs->remove_module('post', 'private');

	// remove all page-related sitemaps
	$bwp_gxs->remove_module('page');

	// add "post format" taxonomy sitemap
	$bwp_gxs->add_module('taxonomy', 'post_format');

	// remove "tag" taxonomy sitemap
	$bwp_gxs->remove_module('taxonomy', 'post_tag');
}

Parameters

array $modules

A list of default modules

array $post_types

A list of public post types. This is the output of https://codex.wordpress.org/Function_Reference/get_post_types

array $taxonomies

A list of public taxonomies.