{"id":2596,"date":"2022-03-22T14:25:38","date_gmt":"2022-03-22T08:55:38","guid":{"rendered":"https:\/\/imageattributespro.com\/?post_type=codex&p=2596"},"modified":"2022-06-03T10:53:21","modified_gmt":"2022-06-03T05:23:21","slug":"iaffpro_custom_attribute_tag_tag_taxonomy","status":"publish","type":"codex","link":"https:\/\/imageattributespro.com\/codex\/iaffpro_custom_attribute_tag_tag_taxonomy\/","title":{"rendered":"iaffpro_custom_attribute_tag_tag_taxonomy"},"content":{"rendered":"
Filter the taxonomy name for The taxonomy name for the WordPress The following code is from Image Attributes Pro version 3.0 and above where the filter is used to extend %tag%<\/code> custom attribute tag to extend it to tags of other post types. By default
%tag%<\/code> fetches the tag of the WordPress
post<\/code> post type.<\/p>
post<\/code>\u2018s tag is
post_tag<\/code> and that of WooCommerce product tag is
product_tag<\/code>.<\/p>
post_tag<\/code>.<\/figcaption><\/figure><\/div>
product_tag<\/code>.<\/figcaption><\/figure><\/div>
\/**\n * Filter $tag_taxonomy_name to extend %tag% custom attribute tag to other post types. \n * \n * Refer 3rd-party\/woocommerce.php for example code.\n * \n * @since 3.0\n * \n * @param $tag_taxonomy_name (string) Name of the taxonomy.\n * @param $post_type (string) will have the post type of the parent post where the image is used. \n *\/\n$tag_taxonomy_name = apply_filters( 'iaffpro_custom_attribute_tag_tag_taxonomy', $tag_taxonomy_name, $post_type );<\/code><\/pre>
Usage In Image Attributes Pro<\/h2>
%tag%<\/code> to WooCommerce products.<\/p>
\/**\n * Add WooCommerce Product tag taxonomy to custom attribute tag %tag%.\n * \n * @since 3.0\n * \n * @param $tag_taxonomy_name (string) Name of the taxonomy.\n * @param $post_type (string) will have the post type of the parent post where the image is used.\n * \n * @return $tag_taxonomy_name (string) WooCommerce product tag taxonomy name ('product_tag') if $post_type is 'product'.\n *\/\nfunction iaffpro_add_wc_product_tag_to_custom_attribute_tag_tag ( $tag_taxonomy_name, $post_type ) {\n\n\t\/\/ Check if post type is WooCommerce product. \n\tif ( strcmp( $post_type, 'product' ) === 0 ) {\n\t\treturn 'product_tag';\n\t}\n\n\treturn $tag_taxonomy_name;\n}\nadd_filter( 'iaffpro_custom_attribute_tag_tag_taxonomy', 'iaffpro_add_wc_product_tag_to_custom_attribute_tag_tag', 10, 2 );<\/code><\/pre>