{"id":2612,"date":"2022-03-22T14:54:29","date_gmt":"2022-03-22T09:24:29","guid":{"rendered":"https:\/\/imageattributespro.com\/?post_type=codex&p=2612"},"modified":"2022-03-22T14:54:30","modified_gmt":"2022-03-22T09:24:30","slug":"iaffpro_custom_attribute_tag_category_names","status":"publish","type":"codex","link":"https:\/\/imageattributespro.com\/codex\/iaffpro_custom_attribute_tag_category_names\/","title":{"rendered":"iaffpro_custom_attribute_tag_category_names"},"content":{"rendered":"\n
The default output of This filter can be used to modify the output of In the following example, the output is modified using the filter. Once the code is applied (for example when added to %category%<\/code> custom attribute tag of Image Attributes Pro is the first category associated with a post. If a post has multiple categories, only one of them will be used while generating image attributes.<\/p>\n\n\n\n
%category%<\/code> custom attribute tag.<\/p>\n\n\n\n
\/**\n * Filter the list of categories returned by %category% custom attribute tag. \n * Default value is first category name.\n * \n * @since 3.0\n * \n * @param $categories[0] (string) The first category available. This is the default value.\n * @param $categories (array) Contains the names of all categories associated with $parent_post_id.\n *\/\nreturn apply_filters( 'iaffpro_custom_attribute_tag_category_names', $categories[0], $categories );<\/code><\/pre>\n\n\n\n
Example Usage<\/h2>\n\n\n\n
functions.php<\/code> of active theme),
%category%<\/code> will output a comma separated list of categories when a post has multiple categories. <\/p>\n\n\n\n
\/**\r\n * Generate a comma separated list of categories to be used as image attributes.\r\n * This modifies the output generated by %category% custom attributes tag in Image Attributes Pro.\r\n * \r\n * @link https:\/\/imageattributespro.com\/codex\/iaffpro_custom_attribute_tag_category_names\/\r\n * \r\n * @param $first_category (string) The first category available.\r\n * @param $categories (array) Contains the names of all categories associated with given post.\r\n * \r\n * @return (string) Comma separated list of all categories.\r\n *\/\r\nfunction prefix_iap_add_all_categories_in_custom_attribute_tag_category( $first_category, $categories ) {\r\n\r\n \/\/ Returns all categories as a comma separated list. \r\n return implode( ',', $categories );\r\n}\r\nadd_filter( 'iaffpro_custom_attribute_tag_category_names', 'prefix_iap_add_all_categories_in_custom_attribute_tag_category', 10, 2 );<\/code><\/pre>\n\n\n\n