• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
Jetpack a2z

Jetpack a2z

Jetpack a2z

  • Home
  • Plugins
  • Blocks
  • Shortcodes
  • APIs
  • Classes
  • Files
  • Hooks
  • Sitemap
  • Blog
Home / APIs / Jetpack_Sitemap_Builder::image_post_to_sitemap_item() – Construct the image sitemap url entry for a WP_Post of image type.

You appear to be a bot. Output may be restricted

Description

Construct the image sitemap url entry for a WP_Post of image type.

Usage

$array = Jetpack_Sitemap_Builder::image_post_to_sitemap_item( $post );

Parameters

$post
( WP_Post ) required – The image post to be processed.
$xml
( array ) required – An XML fragment representing the post URL.
$last_modified
( string ) required – Date post was last modified.

Returns

array

Source

File name: jetpack/modules/sitemaps/sitemap-builder.php
Lines:

1 to 70 of 70
  private function image_post_to_sitemap_item( $post ) {

    
/**
 * Filter condition to allow skipping specific image posts in the sitemap.
 *
 * @module sitemaps
 *
 * @since 4.8.0
 *
 * @param bool    $skip Current boolean. False by default, so no post is skipped.
 * @param WP_POST $post Current post object.
 */
    if ( apply_filters( 'jetpack_sitemap_image_skip_post', false, $post ) ) {
      return array(
        'xml'           => null,
        'last_modified' => null,
      );
    }

    $url = wp_get_attachment_url( $post->ID );

    // Do not include the image if the attached parent is not published.
    // Unattached will be published. Otherwise, will inherit parent status.
    if ( 'publish' !== get_post_status( $post ) ) {
      return array(
        'xml'           => null,
        'last_modified' => null,
      );
    }

    $parent_url = get_permalink( get_post( $post->post_parent ) );
    if ( '' == $parent_url ) { // WPCS: loose comparison ok.
      $parent_url = get_permalink( $post );
    }

    $item_array = array(
      'url' => array(
        'loc'         => $parent_url,
        'lastmod'     => jp_sitemap_datetime( $post->post_modified_gmt ),
        'image:image' => array(
          'image:loc' => $url,
        ),
      ),
    );

    $item_array['url']['image:image']['image:title']   = $post->post_title;
    $item_array['url']['image:image']['image:caption'] = $post->post_excerpt;

    
/**
 * Filter associative array with data to build <url> node
 * and its descendants for current post in image sitemap.
 *
 * @module sitemaps
 *
 * @since 4.8.0
 *
 * @param array $item_array Data to build parent and children nodes for current post.
 * @param int   $post_id Current image post ID.
 */
    $item_array = apply_filters(
      'jetpack_sitemap_image_sitemap_item',
      $item_array,
      $post->ID
    );

    return array(
      'xml'           => $item_array,
      'last_modified' => $post->post_modified_gmt,
    );
  }
 

 View on GitHub View on Trac

Share this:

  • Click to share on Twitter (Opens in new window)
  • Click to share on Facebook (Opens in new window)
  • Click to share on LinkedIn (Opens in new window)
  • Click to share on Pinterest (Opens in new window)

Related

Published: 27 November 2019 | Last updated: 27 November 2019

Primary Sidebar

Information

Function name: Jetpack_Sitemap_Builder::image_post_to_sitemap_item
Class ref: Jetpack_Sitemap_Builder
Plugin ref: Jetpack
Version: 9.2
Sourcefile: modules/sitemaps/sitemap-builder.php
File ref: modules/sitemaps/sitemap-builder.php
Deprecated?: No
API Letters: B,I,J,P,S

Footer

Jetpack a2z
Jetpack a2z
Jetpack a2z
WordPress 5.6
WordPress a2z
WordPress core a2z
Genesis Theme Framework a2z
Jetpack a2z
WordPress develop tests
Easy Digital Downloads a2z
WooCommerce a2z
Yoast SEO a2z
WordPress Blocks

Site:  jetpack.wp-a2z.org
© Copyright Jetpack a2z 2014-2021. All rights reserved.


Website designed and developed by Herb Miller
Proudly powered by WordPress and oik plugins

  • Home
  • Blog
  • Sitemap
  • Sites