Add or Enhance Product Support¶
- Table of contents
- Add or Enhance Product Support
Please note that Add-Meta-Tags has internal support for WooCommerce and Easy-Digital-Downloads e-commerce plugins. Just enable them in the plugin settings.
Read more about:
Detect Custom Products and Add Metadata¶
The following code assumes that e-commerce functionality is added by a plugin named xcom and aims to be an example about how to add Twitter Cards, Opengraph and Schema.org metadata to your product pages.
// Conditional tag that is true when our product page is displayed.
// If such a conditional tag is provided by the e-commerce solution,
// defining such a function is entirely optional.
function is_xcom_product() {
// Check if xcom product page and return true;
}
// Conditional tag that is true when our product group page is displayed.
// If such a conditional tag is provided by the e-commerce solution,
// defining such a function is entirely optional.
function is_xcom_product_group() {
// Check if xcom product group page and return true;
}
// Product page detection for Add-Meta-Tags
function amt_detect_xcom_product() {
if ( is_xcom_product() ) {
return true;
}
return false;
}
add_filter( 'amt_is_product', 'amt_detect_xcom_product' );
// Product group page detection for Add-Meta-Tags
function amt_detect_xcom_product_group() {
if ( is_xcom_product_group() ) {
return true;
}
return false;
}
add_filter( 'amt_is_product_group', 'amt_detect_xcom_product_group' );
// Twitter Cards for xcom products
function amt_product_data_tc_xcom( $metatags, $post ) {
$metatags[] = '<meta name="twitter:label1" content="Genre" />';
$metatags[] = '<meta name="twitter:data1" content="Classic Rock" />';
$metatags[] = '<meta name="twitter:label2" content="Location" />';
$metatags[] = '<meta name="twitter:data2" content="National" />';
return $metatags;
}
add_filter( 'amt_product_data_twitter_cards', 'amt_product_data_tc_xcom', 10, 2 );
// Opengraph for xcom products
function amt_product_data_og_xcom( $metatags, $post ) {
$metatags[] = '<meta property="product:price:amount" content="0.30" />';
$metatags[] = '<meta property="product:price:currency" content="USD" />';
$metatags[] = '<meta property="product:price:amount" content="0.20" />';
$metatags[] = '<meta property="product:price:currency" content="GBP" />';
return $metatags;
}
add_filter( 'amt_product_data_opengraph', 'amt_product_data_og_xcom', 10, 2 );
// Schema.org for xcom products
function amt_product_data_schemaorg_xcom( $metatags, $post ) {
$metatags[] = '<meta itemprop="productID" content="isbn:123-456-789" />';
$metatags[] = '<meta itemprop="priceCurrency" content="USD" />';
$metatags[] = '<meta itemprop="price" content="100.00" />';
return $metatags;
}
add_filter( 'amt_product_data_schemaorg', 'amt_product_data_schemaorg_xcom', 10, 2 );
Customize Metadata for WooCommerce Products¶
// Twitter Cards for WooCommerce products
function amt_custom_woocommerce_tc( $metatags, $post ) {
// Customize meta tags
return $metatags;
}
add_filter( 'amt_product_data_woocommerce_twitter_cards', 'amt_custom_woocommerce_tc', 10, 2 );
// Opengraph for WooCommerce products
function amt_custom_woocommerce_og( $metatags, $post ) {
// Customize meta tags
return $metatags;
}
add_filter( 'amt_product_data_woocommerce_opengraph', 'amt_custom_woocommerce_og', 10, 2 );
// Schema.org for WooCommerce products
function amt_custom_woocommerce_schema( $metatags, $post ) {
// Customize meta tags
return $metatags;
}
add_filter( 'amt_product_data_woocommerce_schemaorg', 'amt_custom_woocommerce_schema', 10, 2 );
Customize Metadata for Easy-Digital-Downloads Products¶
// Twitter Cards for EDD products
function amt_custom_edd_tc( $metatags, $post ) {
// Customize meta tags
return $metatags;
}
add_filter( 'amt_product_data_woocommerce_twitter_cards', 'amt_custom_edd_tc', 10, 2 );
// Opengraph for EDD products
function amt_custom_edd_og( $metatags, $post ) {
// Customize meta tags
return $metatags;
}
add_filter( 'amt_product_data_edd_opengraph', 'amt_custom_edd_og', 10, 2 );
// Schema.org for EDD products
function amt_custom_edd_schema( $metatags, $post ) {
// Customize meta tags
return $metatags;
}
add_filter( 'amt_product_data_woocommerce_schemaorg', 'amt_custom_edd_schema', 10, 2 );