diff options
Diffstat (limited to 'plugins/jetpack/functions.opengraph.php')
-rw-r--r-- | plugins/jetpack/functions.opengraph.php | 34 |
1 files changed, 29 insertions, 5 deletions
diff --git a/plugins/jetpack/functions.opengraph.php b/plugins/jetpack/functions.opengraph.php index 613c59f7..1a7617a0 100644 --- a/plugins/jetpack/functions.opengraph.php +++ b/plugins/jetpack/functions.opengraph.php @@ -5,13 +5,14 @@ * Add Open Graph tags so that Facebook (and any other service that supports them) * can crawl the site better and we provide a better sharing experience. * - * @link http://ogp.me/ - * @link http://developers.facebook.com/docs/opengraph/ + * @link https://ogp.me/ + * @link https://developers.facebook.com/docs/opengraph/ * * @package Jetpack */ add_action( 'wp_head', 'jetpack_og_tags' ); +add_action( 'amp_story_head', 'jetpack_og_tags' ); /** * Outputs Open Graph tags generated by Jetpack. @@ -32,11 +33,16 @@ function jetpack_og_tags() { return; } + $is_amp_response = ( class_exists( 'Jetpack_AMP_Support' ) && Jetpack_AMP_Support::is_amp_request() ); + // Disable the widont filter on WP.com to avoid stray  s. $disable_widont = remove_filter( 'the_title', 'widont' ); - $og_output = "\n<!-- Jetpack Open Graph Tags -->\n"; - $tags = array(); + $og_output = "\n"; + if ( ! $is_amp_response ) { // Because AMP optimizes the order or the nodes in the head. + $og_output .= "<!-- Jetpack Open Graph Tags -->\n"; + } + $tags = array(); /** * Filter the minimum width of the images used in Jetpack Open Graph Meta Tags. @@ -94,6 +100,20 @@ function jetpack_og_tags() { $tags['profile:first_name'] = get_the_author_meta( 'first_name', $author->ID ); $tags['profile:last_name'] = get_the_author_meta( 'last_name', $author->ID ); } + } elseif ( is_archive() ) { + $tags['og:type'] = 'website'; + $tags['og:title'] = wp_get_document_title(); + + $archive = get_queried_object(); + if ( ! empty( $archive ) ) { + if ( is_category() || is_tag() || is_tax() ) { + $tags['og:url'] = get_term_link( $archive->term_id, $archive->taxonomy ); + $tags['og:description'] = $archive->description; + } elseif ( is_post_type_archive() ) { + $tags['og:url'] = get_post_type_archive_link( $archive->name ); + $tags['og:description'] = $archive->description; + } + } } elseif ( is_singular() ) { global $post; $data = $post; // so that we don't accidentally explode the global. @@ -273,7 +293,11 @@ function jetpack_og_tags() { } } } - $og_output .= "\n<!-- End Jetpack Open Graph Tags -->\n"; + + if ( ! $is_amp_response ) { // Because AMP optimizes the order or the nodes in the head. + $og_output .= "\n<!-- End Jetpack Open Graph Tags -->"; + } + $og_output .= "\n"; // This is trusted output or added by a filter. echo $og_output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } |