Filter the taxonomy name for %tag%
custom attribute tag to extend it to tags of other post types. By default %tag%
fetches the tag of the WordPress post
post type.
The taxonomy name for the WordPress post
‘s tag is post_tag
and that of WooCommerce product tag is product_tag
.
/**
* Filter $tag_taxonomy_name to extend %tag% custom attribute tag to other post types.
*
* Refer 3rd-party/woocommerce.php for example code.
*
* @since 3.0
*
* @param $tag_taxonomy_name (string) Name of the taxonomy.
* @param $post_type (string) will have the post type of the parent post where the image is used.
*/
$tag_taxonomy_name = apply_filters( 'iaffpro_custom_attribute_tag_tag_taxonomy', $tag_taxonomy_name, $post_type );
Usage In Image Attributes Pro
The following code is from Image Attributes Pro version 3.0 and above where the filter is used to extend %tag%
to WooCommerce products.
/**
* Add WooCommerce Product tag taxonomy to custom attribute tag %tag%.
*
* @since 3.0
*
* @param $tag_taxonomy_name (string) Name of the taxonomy.
* @param $post_type (string) will have the post type of the parent post where the image is used.
*
* @return $tag_taxonomy_name (string) WooCommerce product tag taxonomy name ('product_tag') if $post_type is 'product'.
*/
function iaffpro_add_wc_product_tag_to_custom_attribute_tag_tag ( $tag_taxonomy_name, $post_type ) {
// Check if post type is WooCommerce product.
if ( strcmp( $post_type, 'product' ) === 0 ) {
return 'product_tag';
}
return $tag_taxonomy_name;
}
add_filter( 'iaffpro_custom_attribute_tag_tag_taxonomy', 'iaffpro_add_wc_product_tag_to_custom_attribute_tag_tag', 10, 2 );
Related: iaffpro_custom_attribute_tag_category_taxonomy
Was this article helpful?
Yes, thanks! 👍Not really 👎