Skip to content

Commit

Permalink
Add custom properties to video XML
Browse files Browse the repository at this point in the history
  • Loading branch information
Jono committed Jan 17, 2023
1 parent 76f3637 commit 635b242
Showing 1 changed file with 40 additions and 12 deletions.
52 changes: 40 additions & 12 deletions docs/features/xml-sitemaps/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ In those cases, you can use the examples below to modify how our sitemaps are ge
/**
* Excludes posts from XML sitemaps.
*
* @return array The IDs of posts to exclude.
* @return array The IDs of posts to exclude
*/
function exclude_posts_from_xml_sitemaps() {
return [ 1, 2, 3 ];
}

add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', 'exclude_posts_from_xml_sitemaps' );
add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', 'exclude_posts_from_xml_sitemaps', 10, 0 );
```

### Exclude a post type
Expand All @@ -32,7 +32,7 @@ add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', 'exclude_posts_from_xml_si
* @param boolean $excluded Whether the post type is excluded by default.
* @param string $post_type The post type to exclude.
*
* @return bool Whether or not a given post type should be excluded.
* @return bool Whether or not a given post type should be excluded
*/
function sitemap_exclude_post_type( $excluded, $post_type ) {
return $post_type === 'recipes';
Expand All @@ -49,7 +49,7 @@ add_filter( 'wpseo_sitemap_exclude_post_type', 'sitemap_exclude_post_type', 10,
* @param boolean $excluded Whether the taxonomy is excluded by default.
* @param string $taxonomy The taxonomy to exclude.
*
* @return bool Whether or not a given taxonomy should be excluded.
* @return bool Whether or not a given taxonomy should be excluded
*/
function sitemap_exclude_taxonomy( $excluded, $taxonomy ) {
return $taxonomy === 'ingredients';
Expand All @@ -65,7 +65,7 @@ add_filter( 'wpseo_sitemap_exclude_taxonomy', 'sitemap_exclude_taxonomy', 10, 2
*
* @param array $users Array of User objects to filter through.
*
* @return array The remaining authors.
* @return array The remaining authors
*/
function sitemap_exclude_authors( $users ) {
return array_filter( $users, function( $user ) {
Expand All @@ -87,7 +87,7 @@ add_filter( 'wpseo_sitemap_exclude_author', 'sitemap_exclude_authors', 10, 1 );
*
* @param array $terms Array of term IDs already excluded.
*
* @return array The terms to exclude.
* @return array The terms to exclude
*/
function sitemap_exclude_terms( $terms ) {
return [ 3, 11 ];
Expand All @@ -102,6 +102,8 @@ add_filter( 'wpseo_exclude_from_sitemap_by_term_ids', 'sitemap_exclude_terms', 1
```php
/**
* Adds an XML sitemap for a custom post type.
*
* @return void
*/
function enable_custom_sitemap() {
global $wpseo_sitemaps;
Expand All @@ -110,7 +112,7 @@ function enable_custom_sitemap() {
}
}

add_action( 'init', 'enable_custom_sitemap' );
add_action( 'init', 'enable_custom_sitemap', 10, 0 );
```

### Add additional/external XML sitemaps to the XML sitemap index
Expand All @@ -120,7 +122,7 @@ add_action( 'init', 'enable_custom_sitemap' );
*
* @param string $sitemap_custom_items XML describing one or more custom sitemaps.
*
* @return string The XML sitemap index with the additional XML.
* @return string The XML sitemap index with the additional XML
*/
function add_sitemap_custom_items( $sitemap_custom_items ) {
$sitemap_custom_items .= '
Expand All @@ -131,7 +133,7 @@ function add_sitemap_custom_items( $sitemap_custom_items ) {
return $sitemap_custom_items;
}

add_filter( 'wpseo_sitemap_index', 'add_sitemap_custom_items' );
add_filter( 'wpseo_sitemap_index', 'add_sitemap_custom_items', 10, 1);
```

## Misc
Expand All @@ -144,7 +146,7 @@ add_filter( 'wpseo_sitemap_index', 'add_sitemap_custom_items' );
* @param string $url The URL to modify.
* @param WP_Post $post The post object.
*
* @return string The modified URL.
* @return string The modified URL
*/
function sitemap_post_url( $url, $post ) {
if ( $post->post_type === 'guest_authors' ) {
Expand All @@ -162,11 +164,37 @@ add_filter( 'wpseo_xml_sitemap_post_url', 'sitemap_post_url', 10, 2 );
/**
* Alters the number of entries in each XML sitemap.
*
* @return integer The maximum entries per sitemap.
* @return integer The maximum entries per sitemap
*/
function max_entries_per_sitemap() {
return 100;
}

add_filter( 'wpseo_sitemap_entries_per_page', 'max_entries_per_sitemap' );
add_filter( 'wpseo_sitemap_entries_per_page', 'max_entries_per_sitemap', 10, 0 );
```

### Add extra properties to the <video:video> container
```php
/**
* Adds an example <video:live> property to a <video:video> container for a particular post
*
* @param string $property A placeholder for a custom property.
* @param int $post_id The post ID.
*
* @return string The property to add
*/
function add_video_live_property($property = '', $post_id ) {

// Bail if this isn't the example post we want to modify.
if ( $post_id !== 12345 ) {
return $property;
}

// Set our custom property.
$property = '<video:live>yes</video:live>';

return $property;
}

add_filter( 'wpseo_video_item', 'add_video_live_property' );
```

0 comments on commit 635b242

Please sign in to comment.