{"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 %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

This filter can be used to modify the output of %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

In the following example, the output is modified using the filter. Once the code is applied (for example when added to 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

Related: iaffpro_custom_attribute_tag_tag_names<\/a><\/code><\/p>\n","protected":false},"excerpt":{"rendered":"

The default output of %category% 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. This filter can be used to modify the output of %category% custom attribute tag.<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"open","ping_status":"open","template":"","format":"standard","meta":[],"tags":[],"codex-type":[27],"_links":{"self":[{"href":"https:\/\/imageattributespro.com\/wp-json\/wp\/v2\/codex\/2612"}],"collection":[{"href":"https:\/\/imageattributespro.com\/wp-json\/wp\/v2\/codex"}],"about":[{"href":"https:\/\/imageattributespro.com\/wp-json\/wp\/v2\/types\/codex"}],"author":[{"embeddable":true,"href":"https:\/\/imageattributespro.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/imageattributespro.com\/wp-json\/wp\/v2\/comments?post=2612"}],"version-history":[{"count":1,"href":"https:\/\/imageattributespro.com\/wp-json\/wp\/v2\/codex\/2612\/revisions"}],"predecessor-version":[{"id":2613,"href":"https:\/\/imageattributespro.com\/wp-json\/wp\/v2\/codex\/2612\/revisions\/2613"}],"wp:attachment":[{"href":"https:\/\/imageattributespro.com\/wp-json\/wp\/v2\/media?parent=2612"}],"wp:term":[{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/imageattributespro.com\/wp-json\/wp\/v2\/tags?post=2612"},{"taxonomy":"codex-type","embeddable":true,"href":"https:\/\/imageattributespro.com\/wp-json\/wp\/v2\/codex-type?post=2612"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}