本文整理汇总了PHP中amt_get_content_description函数的典型用法代码示例。如果您正苦于以下问题:PHP amt_get_content_description函数的具体用法?PHP amt_get_content_description怎么用?PHP amt_get_content_description使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了amt_get_content_description函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: amt_content_description
function amt_content_description()
{
$post = apply_filters('amt_get_queried_object', get_queried_object());
if (!is_null($post)) {
echo amt_get_content_description($post);
}
}
示例2: amt_content_description
function amt_content_description()
{
$post = get_queried_object();
if (!is_null($post)) {
echo amt_get_content_description($post);
}
}
示例3: amt_content_description
function amt_content_description()
{
$options = get_option("add_meta_tags_opts");
$post = amt_get_queried_object($options);
if (!is_null($post)) {
echo amt_get_content_description($post);
}
}
示例4: amt_add_basic_metadata_head
/**
* Generates basic metadata for the head area.
*
*/
function amt_add_basic_metadata_head($post, $attachments, $embedded_media, $options)
{
$do_description = $options["auto_description"] == "1" ? true : false;
$do_keywords = $options["auto_keywords"] == "1" ? true : false;
$do_noodp_description = $options["noodp_description"] == "1" ? true : false;
// Array to store metadata
$metadata_arr = array();
// Robots Meta Tag.
$robots_content = '';
if ($do_noodp_description && (is_front_page() || is_singular())) {
// Add NOODP on posts and pages
$robots_content = 'NOODP,NOYDIR';
// Allow filtering of the robots meta tag content.
$robots_content = apply_filters('amt_robots_data', $robots_content);
}
// Add a robots meta tag if its content is not empty.
if (!empty($robots_content)) {
$metadata_arr[] = '<meta name="robots" content="' . $robots_content . '" />';
}
// Default front page displaying latest posts
if (amt_is_default_front_page()) {
// Description and Keywords from the Add-Meta-Tags settings override
// default behaviour.
// Description
if ($do_description) {
// Use the site description from the Add-Meta-Tags settings.
// Fall back to the blog description.
$site_description = $options["site_description"];
if (empty($site_description)) {
// Alternatively, use the blog description
// Here we sanitize the provided description for safety
$site_description = sanitize_text_field(amt_sanitize_description(get_bloginfo('description')));
}
// If we have a description, use it in the description meta-tag of the front page
if (!empty($site_description)) {
// Note: Contains multipage information through amt_process_paged()
$metadata_arr[] = '<meta name="description" content="' . esc_attr(amt_process_paged($site_description)) . '" />';
}
}
// Keywords
if ($do_keywords) {
// Use the site keywords from the Add-Meta-Tags settings.
// Fall back to the blog categories.
$site_keywords = $options["site_keywords"];
if (empty($site_keywords)) {
// Alternatively, use the blog categories
// Here we sanitize the provided keywords for safety
$site_keywords = sanitize_text_field(amt_sanitize_keywords(amt_get_all_categories()));
}
// If we have keywords, use them in the keywords meta-tag of the front page
if (!empty($site_keywords)) {
$metadata_arr[] = '<meta name="keywords" content="' . esc_attr($site_keywords) . '" />';
}
}
// Attachments
} elseif (is_attachment()) {
// has to be before is_singular() since is_singular() is true for attachments.
// Description
if ($do_description) {
$description = amt_get_content_description($post, $auto = $do_description);
if (!empty($description)) {
// Note: Contains multipage information through amt_process_paged()
$metadata_arr[] = '<meta name="description" content="' . esc_attr(amt_process_paged($description)) . '" />';
}
}
// No keywords
// Content pages and static pages used as "front page" and "posts page"
// This also supports products via is_singular()
} elseif (is_singular() || amt_is_static_front_page() || amt_is_static_home()) {
// Description
if ($do_description) {
$description = amt_get_content_description($post, $auto = $do_description);
if (!empty($description)) {
// Note: Contains multipage information through amt_process_paged()
$metadata_arr[] = '<meta name="description" content="' . esc_attr(amt_process_paged($description)) . '" />';
}
}
// Keywords
if ($do_keywords) {
$keywords = amt_get_content_keywords($post, $auto = $do_keywords);
if (!empty($keywords)) {
$metadata_arr[] = '<meta name="keywords" content="' . esc_attr($keywords) . '" />';
// Static Posts Index Page
// If no keywords have been set in the metabox and this is the static page,
// which displayes the latest posts, use the categories of the posts in the loop.
} elseif (amt_is_static_home()) {
// Here we sanitize the provided keywords for safety
$cats_from_loop = sanitize_text_field(amt_sanitize_keywords(implode(', ', amt_get_categories_from_loop())));
if (!empty($cats_from_loop)) {
$metadata_arr[] = '<meta name="keywords" content="' . esc_attr($cats_from_loop) . '" />';
}
}
}
// 'news_keywords'
$newskeywords = amt_get_post_meta_newskeywords($post->ID);
if (!empty($newskeywords)) {
//.........这里部分代码省略.........
示例5: amt_get_jsonld_schemaorg_image_array
/**
* Return an array of Schema.org metatags for the provided $image object.
* By default, returns metadata for the 'medium' sized version of the image.
*/
function amt_get_jsonld_schemaorg_image_array($options, $image_data, $size = 'medium', $is_representative = false)
{
//
// $image_data can be:
//
// 1. An array with the following data:
//
// 'id' => null, // post ID of attachment
// 'url' => null,
// 'width' => null,
// 'height' => null,
// 'type' => null,
//
// 2. An attachment ID (integer)
//
// 3. An attachment object (post object) (Usually ths is the case in the schema.org generators
//
//var_dump($image_data);
$metadata_arr = array();
$image = null;
if (is_array($image_data) && !is_null($image_data['url'])) {
// Here we process the image data as retrieved from the special notation of the image's URL.
// No size information is taken into account in this case.
// Schema.org type
$metadata_arr['@type'] = 'ImageObject';
// Image tags
$metadata_arr['url'] = esc_url($image_data['url']);
$metadata_arr['contentUrl'] = esc_url($image_data['url']);
if (apply_filters('amt_extended_image_tags', true)) {
if (!is_null($image_data['width'])) {
$metadata_arr['width'] = esc_attr($image_data['width']);
}
if (!is_null($image_data['height'])) {
$metadata_arr['height'] = esc_attr($image_data['height']);
}
if (!is_null($image_data['type'])) {
$metadata_arr['encodingFormat'] = esc_attr($image_data['type']);
}
}
return $metadata_arr;
} elseif (is_array($image_data) && is_numeric($image_data['id'])) {
// The attachment ID exists in the array's 'id' item.
$image = get_post(absint($image_data['id']));
} elseif (is_numeric($image_data)) {
// Image data is the attachment ID (integer)
$image = get_post(absint($image_data));
} elseif (is_object($image_data) && isset($image_data->ID)) {
// Image data is the attachment itself.
$image = $image_data;
}
if (is_null($image) || !is_object($image) || !isset($image->ID)) {
return $metadata_arr;
}
// Process the image attachment and generate meta tags.
// Schema.org type
$metadata_arr['@type'] = 'ImageObject';
// Get the image object <- Already have it
//$image = get_post( $post_id );
// Data for image attachments
$image_meta = wp_get_attachment_metadata($image->ID);
// contains info about all sizes
// We use wp_get_attachment_image_src() since it constructs the URLs
$thumbnail_meta = wp_get_attachment_image_src($image->ID, 'thumbnail');
$main_size_meta = wp_get_attachment_image_src($image->ID, $size);
// name (title)
$metadata_arr['name'] = esc_attr(strip_tags(get_the_title($image->ID)));
// OLD name (title)
//$image_title = sanitize_text_field( $image->post_title );
//if ( ! empty( $image_title ) ) {
// $metadata_arr[] = '<meta itemprop="name" content="' . esc_attr( $image_title ) . '" />';
//}
// URL (links to image file)
//$metadata_arr['url'] = esc_url_raw( get_permalink( $image->ID ) );
$metadata_arr['url'] = esc_url_raw($main_size_meta[0]);
// sameAS (links to attachment page)
$metadata_arr['sameAs'] = esc_url_raw(get_permalink($image->ID));
// Description (generated from $image->post_content. See: amt_get_the_excerpt()
$image_description = amt_get_content_description($image);
if (!empty($image_description)) {
$metadata_arr['description'] = esc_attr($image_description);
}
// thumbnail url
$metadata_arr['thumbnailUrl'] = esc_url_raw($thumbnail_meta[0]);
// main image
$metadata_arr['contentUrl'] = esc_url_raw($main_size_meta[0]);
if (apply_filters('amt_extended_image_tags', true)) {
$metadata_arr['width'] = esc_attr($main_size_meta[1]);
$metadata_arr['height'] = esc_attr($main_size_meta[2]);
$metadata_arr['encodingFormat'] = esc_attr(get_post_mime_type($image->ID));
}
// caption
// Here we sanitize the provided description for safety
$image_caption = sanitize_text_field($image->post_excerpt);
if (!empty($image_caption)) {
$metadata_arr['caption'] = esc_attr($image_caption);
}
//.........这里部分代码省略.........
示例6: amt_add_opengraph_metadata_head
/**
* Generates Opengraph metadata.
*
* Currently for:
* - home page
* - author archive
* - content
*/
function amt_add_opengraph_metadata_head($post, $attachments, $embedded_media, $options)
{
if (apply_filters('amt_exclude_opengraph_metadata', false)) {
return array();
}
$do_auto_opengraph = $options["auto_opengraph"] == "1" ? true : false;
if (!$do_auto_opengraph) {
return array();
}
$metadata_arr = array();
// fb:app_id & fb:admins
// We currently let users add the full meta tags for fb:app_id and fb:admins in the site wide meta tags box.
// fb:app_id appears everywhere
//if ( ! empty($options['social_main_facebook_app_id']) ) {
// $metadata_arr[] = '<meta property="fb:app_id" content="' . esc_attr( $options['social_main_facebook_app_id'] ) . '" />';
//}
// fb:admins appear everywhere
//if ( ! empty($options['social_main_facebook_admins']) ) {
// $fb_admins_arr = explode(',', $options['social_main_facebook_admins']);
// foreach ( $fb_admins_arr as $fb_admin ) {
// $metadata_arr[] = '<meta property="fb:admins" content="' . esc_attr( trim($fb_admin) ) . '" />';
// }
//}
// no publisher meta tag for facebook, unless it is content
// Custom content override
if (amt_is_custom($post, $options)) {
// Return metadata with:
// add_filter( 'amt_custom_metadata_opengraph', 'my_function', 10, 5 );
// Return an array of meta tags. Array item format: ['key_can_be_whatever'] = '<meta name="foo" content="bar" />'
$metadata_arr = apply_filters('amt_custom_metadata_opengraph', $metadata_arr, $post, $options, $attachments, $embedded_media);
// Default front page displaying the latest posts
} elseif (amt_is_default_front_page()) {
// Type
$metadata_arr[] = '<meta property="og:type" content="website" />';
// Site Name
$metadata_arr[] = '<meta property="og:site_name" content="' . esc_attr(get_bloginfo('name')) . '" />';
// Title - Note: Contains multipage information
$metadata_arr['og:title'] = '<meta property="og:title" content="' . esc_attr(amt_get_title_for_metadata($options, $post)) . '" />';
// URL - Note: different method to get the permalink on paged archives
if (is_paged()) {
$metadata_arr[] = '<meta property="og:url" content="' . esc_url_raw(get_pagenum_link(get_query_var('paged'))) . '" />';
} else {
$metadata_arr[] = '<meta property="og:url" content="' . esc_url_raw(trailingslashit(get_bloginfo('url'))) . '" />';
}
// Site description - Note: Contains multipage information through amt_process_paged()
$site_description = amt_get_site_description($options);
if (empty($site_description)) {
$site_description = get_bloginfo('description');
}
if (!empty($site_description)) {
$metadata_arr[] = '<meta property="og:description" content="' . esc_attr(amt_process_paged($site_description)) . '" />';
}
// Locale
$metadata_arr[] = '<meta property="og:locale" content="' . esc_attr(str_replace('-', '_', amt_get_language_site($options))) . '" />';
// Site Image
// Use the default image, if one has been set.
$image_data = amt_get_default_image_data();
if (!empty($image_data)) {
$image_size = apply_filters('amt_image_size_index', 'full');
$image_meta_tags = amt_get_opengraph_image_metatags($options, $image_data, $size = $image_size);
if (!empty($image_meta_tags)) {
$metadata_arr = array_merge($metadata_arr, $image_meta_tags);
}
}
// Front page using a static page
// Note: might also contain a listing of posts which may be paged, so use amt_process_paged()
} elseif (amt_is_static_front_page()) {
// Type
if ($options['author_profile_source'] == 'frontpage') {
// The front page is treated as the profile page.
$metadata_arr[] = '<meta property="og:type" content="profile" />';
} else {
$metadata_arr[] = '<meta property="og:type" content="website" />';
}
// Site Name
$metadata_arr[] = '<meta property="og:site_name" content="' . esc_attr(get_bloginfo('name')) . '" />';
// Title - Note: Contains multipage information
$metadata_arr['og:title'] = '<meta property="og:title" content="' . esc_attr(amt_get_title_for_metadata($options, $post)) . '" />';
// URL - Note: different method to get the permalink on paged archives
if (is_paged()) {
$metadata_arr[] = '<meta property="og:url" content="' . esc_url_raw(get_pagenum_link(get_query_var('paged'))) . '" />';
} else {
$metadata_arr[] = '<meta property="og:url" content="' . esc_url_raw(trailingslashit(get_bloginfo('url'))) . '" />';
}
// Site Description - Note: Contains multipage information through amt_process_paged()
$content_desc = amt_get_content_description($post);
if (!empty($content_desc)) {
// Use the pages custom description
$metadata_arr[] = '<meta property="og:description" content="' . esc_attr(amt_process_paged($content_desc)) . '" />';
} elseif (get_bloginfo('description')) {
// Alternatively use the blog's description
$metadata_arr[] = '<meta property="og:description" content="' . esc_attr(amt_process_paged(get_bloginfo('description'))) . '" />';
//.........这里部分代码省略.........
示例7: amt_add_basic_metadata_head
//.........这里部分代码省略.........
// Fall back to the blog description.
$site_description = amt_get_site_description($options);
if (empty($site_description)) {
// Alternatively, use the blog description
// Here we sanitize the provided description for safety
$site_description = sanitize_text_field(amt_sanitize_description(get_bloginfo('description')));
}
// If we have a description, use it in the description meta-tag of the front page
if (!empty($site_description)) {
// Note: Contains multipage information through amt_process_paged()
$metadata_arr['basic:description'] = '<meta name="description" content="' . esc_attr(amt_process_paged($site_description)) . '" />';
}
}
// Keywords
if ($do_keywords) {
// Use the site keywords from the Add-Meta-Tags settings.
// Fall back to the blog categories.
$site_keywords = amt_get_site_keywords($options);
if (empty($site_keywords)) {
// Alternatively, use the blog categories
// Here we sanitize the provided keywords for safety
$site_keywords = sanitize_text_field(amt_sanitize_keywords(amt_get_all_categories()));
}
// If we have keywords, use them in the keywords meta-tag of the front page
if (!empty($site_keywords)) {
$metadata_arr['basic:keywords'] = '<meta name="keywords" content="' . esc_attr($site_keywords) . '" />';
}
}
// Attachments
} elseif (is_attachment()) {
// has to be before is_singular() since is_singular() is true for attachments.
// Description
if ($do_description) {
$description = amt_get_content_description($post, $auto = $do_description);
if (!empty($description)) {
// Note: Contains multipage information through amt_process_paged()
$metadata_arr['basic:description'] = '<meta name="description" content="' . esc_attr(amt_process_paged($description)) . '" />';
}
}
// No keywords
// Content pages and static pages used as "front page" and "posts page"
// This also supports products via is_singular()
} elseif (is_singular() || amt_is_static_front_page() || amt_is_static_home()) {
// Description
if ($do_description) {
$description = amt_get_content_description($post, $auto = $do_description);
if (!empty($description)) {
// Note: Contains multipage information through amt_process_paged()
$metadata_arr['basic:description'] = '<meta name="description" content="' . esc_attr(amt_process_paged($description)) . '" />';
}
}
// Keywords
if ($do_keywords) {
$keywords = amt_get_content_keywords($post, $auto = $do_keywords);
if (!empty($keywords)) {
$metadata_arr['basic:keywords'] = '<meta name="keywords" content="' . esc_attr($keywords) . '" />';
// Static Posts Index Page
// If no keywords have been set in the metabox and this is the static page,
// which displayes the latest posts, use the categories of the posts in the loop.
} elseif (amt_is_static_home()) {
// Here we sanitize the provided keywords for safety
$cats_from_loop = sanitize_text_field(amt_sanitize_keywords(implode(', ', amt_get_categories_from_loop())));
if (!empty($cats_from_loop)) {
$metadata_arr['basic:keywords'] = '<meta name="keywords" content="' . esc_attr($cats_from_loop) . '" />';
}
}
示例8: amt_add_twitter_cards_metadata_head
//.........这里部分代码省略.........
if (!empty($posttype_image_url)) {
$image_data = amt_get_image_data($posttype_image_url);
if (!empty($image_data)) {
$image_size = apply_filters('amt_image_size_index', 'full');
$image_meta_tags = amt_get_twitter_cards_image_metatags($options, $image_data, $size = $image_size);
if (!empty($image_meta_tags)) {
$metadata_arr = array_merge($metadata_arr, $image_meta_tags);
}
}
//$metadata_arr[] = '<meta name="twitter:image" content="' . esc_url_raw( $posttype_image_url ) . '" />';
}
}
}
return $metadata_arr;
}
// Further check (required in some reported cases)
// Go no further if the content type does not validate is_singular().
if (!is_singular()) {
return array();
}
// Products
// A 'product' Twitter Card is generated. See: https://dev.twitter.com/cards/types/product
if (amt_is_product()) {
// Type
$metadata_arr[] = '<meta name="twitter:card" content="product" />';
// Author and Publisher
$metadata_arr = array_merge($metadata_arr, amt_get_twitter_cards_author_publisher_metatags($options, $post));
// Title
// Note: Contains multipage information
//$metadata_arr[] = '<meta name="twitter:title" content="' . esc_attr( amt_process_paged( strip_tags( get_the_title($post->ID) ) ) ) . '" />';
$metadata_arr['twitter:title'] = '<meta name="twitter:title" content="' . esc_attr(amt_get_title_for_metadata($options, $post)) . '" />';
// Description - We use the description defined by Add-Meta-Tags
// Note: Contains multipage information through amt_process_paged()
$content_desc = amt_get_content_description($post);
if (!empty($content_desc)) {
$metadata_arr[] = '<meta name="twitter:description" content="' . esc_attr(amt_process_paged($content_desc)) . '" />';
}
// Image
// Use the featured image or the default image as a fallback.
// Set to true if image meta tags have been added to the card, so that it does not
// search for any more images.
$image_metatags_added = false;
// First check if a global image override URL has been entered.
// If yes, use this image URL and override all other images.
$image_data = amt_get_image_data(amt_get_post_meta_image_url($post->ID));
if (!empty($image_data)) {
$image_size = apply_filters('amt_image_size_product', 'full');
$image_meta_tags = amt_get_twitter_cards_image_metatags($options, $image_data, $size = $image_size);
if (!empty($image_meta_tags)) {
$metadata_arr = array_merge($metadata_arr, $image_meta_tags);
}
//$global_image_override_url = amt_get_post_meta_image_url($post->ID);
//if ( $image_metatags_added === false && ! empty( $global_image_override_url ) ) {
// $metadata_arr[] = '<meta name="twitter:image" content="' . esc_url_raw( $global_image_override_url ) . '" />';
// Images have been found.
$image_metatags_added = true;
}
// Set the image size to use
$image_size = apply_filters('amt_image_size_product', 'full');
// If the content has a featured image, then we use it.
if ($image_metatags_added === false && function_exists('has_post_thumbnail') && has_post_thumbnail($post->ID)) {
$main_size_meta = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), $image_size);
$metadata_arr[] = '<meta name="twitter:image" content="' . esc_url_raw($main_size_meta[0]) . '" />';
if (apply_filters('amt_extended_image_tags', true)) {
$metadata_arr[] = '<meta name="twitter:image:width" content="' . esc_attr($main_size_meta[1]) . '" />';
$metadata_arr[] = '<meta name="twitter:image:height" content="' . esc_attr($main_size_meta[2]) . '" />';
示例9: amt_add_dublin_core_metadata_head
function amt_add_dublin_core_metadata_head($post, $attachments, $embedded_media, $options)
{
if (apply_filters('amt_exclude_dublin_core_metadata', false)) {
return array();
}
$metadata_arr = array();
$do_auto_dublincore = $options["auto_dublincore"] == "1" ? true : false;
if (!$do_auto_dublincore) {
return $metadata_arr;
}
// Custom content override
if (amt_is_custom($post, $options)) {
// Return metadata with:
// add_filter( 'amt_custom_metadata_dublin_core', 'my_function', 10, 5 );
// Return an array of meta tags. Array item format: ['key_can_be_whatever'] = '<meta name="foo" content="bar" />'
$metadata_arr = apply_filters('amt_custom_metadata_dublin_core', $metadata_arr, $post, $options, $attachments, $embedded_media);
return $metadata_arr;
}
if (!is_singular() || is_front_page()) {
// is_front_page() is used for the case in which a static page is used as the front page.
// Dublin Core metadata has a meaning for content only.
return array();
}
// The Dublin Core metadata generator does not support products or product groups.
if (amt_is_product() || amt_is_product_group()) {
return array();
}
// Title
// Note: Contains multipage information through amt_process_paged()
$metadata_arr['dcterms.title'] = '<meta name="dcterms.title" content="' . esc_attr(amt_get_title_for_metadata($options, $post)) . '" />';
// Resource identifier - Uses amt_get_permalink_for_multipage()
$metadata_arr[] = '<meta name="dcterms.identifier" content="' . esc_url_raw(amt_get_permalink_for_multipage($post)) . '" />';
$metadata_arr[] = '<meta name="dcterms.creator" content="' . esc_attr(amt_get_dublin_core_author_notation($post)) . '" />';
//$metadata_arr[] = '<meta name="dcterms.date" content="' . esc_attr( amt_iso8601_date($post->post_date) ) . '" />';
$metadata_arr[] = '<meta name="dcterms.created" content="' . esc_attr(amt_iso8601_date($post->post_date)) . '" />';
$metadata_arr[] = '<meta name="dcterms.available" content="' . esc_attr(amt_iso8601_date($post->post_date)) . '" />';
//$metadata_arr[] = '<meta name="dcterms.issued" content="' . esc_attr( amt_iso8601_date($post->post_date) ) . '" />';
$metadata_arr[] = '<meta name="dcterms.modified" content="' . esc_attr(amt_iso8601_date($post->post_modified)) . '" />';
// Description
// We use the same description as the ``description`` meta tag.
// Note: Contains multipage information through amt_process_paged()
$content_desc = amt_get_content_description($post);
if (!empty($content_desc)) {
$metadata_arr[] = '<meta name="dcterms.description" content="' . esc_attr(amt_process_paged($content_desc)) . '" />';
}
// Keywords
if (!is_attachment()) {
// Attachments do not support keywords
// dcterms.subject - one for each keyword.
$keywords = explode(',', amt_get_content_keywords($post));
foreach ($keywords as $subject) {
$subject = trim($subject);
if (!empty($subject)) {
$metadata_arr[] = '<meta name="dcterms.subject" content="' . esc_attr($subject) . '" />';
}
}
}
$metadata_arr[] = '<meta name="dcterms.language" content="' . esc_attr(amt_get_language_content($options, $post)) . '" />';
$metadata_arr[] = '<meta name="dcterms.publisher" content="' . esc_url_raw(trailingslashit(get_bloginfo('url'))) . '" />';
// Copyright page
$copyright_url = amt_get_site_copyright_url($options);
if (empty($copyright_url)) {
$copyright_url = trailingslashit(get_bloginfo('url'));
}
if (!empty($copyright_url)) {
$metadata_arr[] = '<meta name="dcterms.rights" content="' . esc_url_raw($copyright_url) . '" />';
}
// License
$license_url = '';
// The following requires creative commons configurator
if (function_exists('bccl_get_license_url')) {
$license_url = bccl_get_license_url();
}
// Allow filtering of the license URL
$license_url = apply_filters('amt_dublin_core_license', $license_url, $post->ID);
// Add metatag if $license_url is not empty.
if (!empty($license_url)) {
$metadata_arr[] = '<meta name="dcterms.license" content="' . esc_url_raw($license_url) . '" />';
}
// Coverage
$metadata_arr[] = '<meta name="dcterms.coverage" content="World" />';
if (is_attachment()) {
$mime_type = get_post_mime_type($post->ID);
//$attachment_type = strstr( $mime_type, '/', true );
// See why we do not use strstr(): http://www.codetrax.org/issues/1091
$attachment_type = preg_replace('#\\/[^\\/]*$#', '', $mime_type);
$metadata_arr[] = '<meta name="dcterms.isPartOf" content="' . esc_url_raw(get_permalink($post->post_parent)) . '" />';
if ('image' == $attachment_type) {
$metadata_arr[] = '<meta name="dcterms.type" content="Image" />';
$metadata_arr[] = '<meta name="dcterms.format" content="' . $mime_type . '" />';
} elseif ('video' == $attachment_type) {
$metadata_arr[] = '<meta name="dcterms.type" content="MovingImage" />';
$metadata_arr[] = '<meta name="dcterms.format" content="' . $mime_type . '" />';
} elseif ('audio' == $attachment_type) {
$metadata_arr[] = '<meta name="dcterms.type" content="Sound" />';
$metadata_arr[] = '<meta name="dcterms.format" content="' . $mime_type . '" />';
}
// Finally add the hasFormat
$metadata_arr[] = '<meta name="dcterms.hasFormat" content="' . esc_url_raw(wp_get_attachment_url($post->ID)) . '" />';
} else {
//.........这里部分代码省略.........
示例10: amt_get_jsonld_schemaorg_image_array
/**
* Return an array of Schema.org metatags for the provided $image object.
* By default, returns metadata for the 'medium' sized version of the image.
*/
function amt_get_jsonld_schemaorg_image_array($image, $size = 'medium', $is_representative = false)
{
$metadata_arr = array();
// Schema.org type
$metadata_arr['@type'] = 'ImageObject';
// Get the image object <- Already have it
//$image = get_post( $post_id );
// Data for image attachments
$image_meta = wp_get_attachment_metadata($image->ID);
// contains info about all sizes
// We use wp_get_attachment_image_src() since it constructs the URLs
$thumbnail_meta = wp_get_attachment_image_src($image->ID, 'thumbnail');
$main_size_meta = wp_get_attachment_image_src($image->ID, $size);
// name (title)
$metadata_arr['name'] = esc_attr(get_the_title($image->ID));
// OLD name (title)
//$image_title = sanitize_text_field( $image->post_title );
//if ( ! empty( $image_title ) ) {
// $metadata_arr[] = '<meta itemprop="name" content="' . esc_attr( $image_title ) . '" />';
//}
// URL (links to attachment page)
$metadata_arr['url'] = esc_url_raw(get_permalink($image->ID));
// Description (generated from $image->post_content. See: amt_get_the_excerpt()
$image_description = amt_get_content_description($image);
if (!empty($image_description)) {
$metadata_arr['description'] = esc_attr($image_description);
}
// thumbnail url
$metadata_arr['thumbnailUrl'] = esc_url_raw($thumbnail_meta[0]);
// main image
$metadata_arr['contentUrl'] = esc_url_raw($main_size_meta[0]);
if (apply_filters('amt_extended_image_tags', true)) {
$metadata_arr['width'] = esc_attr($main_size_meta[1]);
$metadata_arr['height'] = esc_attr($main_size_meta[2]);
$metadata_arr['encodingFormat'] = esc_attr(get_post_mime_type($image->ID));
}
// caption
// Here we sanitize the provided description for safety
$image_caption = sanitize_text_field($image->post_excerpt);
if (!empty($image_caption)) {
$metadata_arr['caption'] = esc_attr($image_caption);
}
// alt
// Here we sanitize the provided description for safety
$image_alt = sanitize_text_field(get_post_meta($image->ID, '_wp_attachment_image_alt', true));
if (!empty($image_alt)) {
$metadata_arr['text'] = esc_attr($image_alt);
}
if ($is_representative === true) {
// representativeOfPage - Boolean - Indicates whether this image is representative of the content of the page.
$metadata_arr['representativeOfPage'] = 'True';
}
return $metadata_arr;
}