This should work for the rel
attribute:
/**
* Create a rel attribute from the image categories
*
* @see http://wordpress.stackexchange.com/a/158024/26350
*/
add_filter( 'get_image_tag',
function( $html, $id )
{
$rel = array();
foreach( (array) get_the_category( $id ) as $cat )
{
$rel[] = $cat->slug;
}
return str_ireplace(
'<img ',
sprintf( '<img rel="%s" ', join( ' ', $rel ) ),
$html
);
}
, 10, 2 );
where we use the get_image_tag
filter to modify the inserted image HTML.
Ps: I just tested this successfully on my WordPress 3.9.2 install, where I used the following code snippet:
add_action( 'init',
function()
{
register_taxonomy_for_object_type( 'category', 'attachment' );
}
);
to activate the categories for attachments.
Related Posts:
- How to add classes to images based on their categories?
- Auto delete WordPress images/thumbnails (all sizes) and featured after X days/hours, or similar?
- Display random categories on the front page (Finding and Editing Theme Functions)
- remove links from images using functions.php
- Best way to programatically add “rel” attributes to page and post images
- Actions according to image type and size
- Automatically wrap multiple images in div
- Image rotation fails to regenerate custom sized thumbnail
- Twentyten Child Theme: header images display messed up in admin panel
- Display images that are not in the content
- Redirect to another page using contact form 7? [closed]
- How to hide image-url if no attachment?
- What are the meta fields for an attachment?
- Randomizing wp_tag_cloud() in child theme
- Add attribute only to first image of every post via functions.php
- Get Attachment Category Name
- Different image using srcset function
- Auto delete content in specific folder inside media library
- How to update an image attachment’s alt text from a custom field when saving a post?
- Remove all video attachment, both files and post/postmeta from database?
- Replace image attributes for lazyload plugin on image elements with specific class
- Open image size links in a page instead of direct image link
- How to crop image in WordPress with aspect ratio for any size of image
- Insert a field with PREG_REPLACE – strange behaviour
- How to echo Widget Title in Custom Frontend-Template Box
- wp_get_attachment_image_src returns image on main domain, false on subdomain
- New checkbox in custom widget isn’t saving data
- Linking Javascript in functions.php file
- how to display a page before the home page
- loginout function customization
- Retrieve First Image Function
- Custom Image Size in Insert Media
- How to add icon over specific thumb
- Featured Image keeps cropping
- Prevent creating multiple image resizes in twentytwelve template
- Conditional function for excluding first image from content, not working
- Function to check if custom page is used by page?
- Using add_image_size in functions.php to get original uploaded file
- get_image_tag() html output : empty src attribute
- How d0 i get the number of attachments in the post
- implementing a centralized content “show-do-not-show” toggle?
- How would I make a function to dynamically determine if user is logged to change navigation menu text?
- WordPress Categories: Function using custom SQL to return array of specific category IDs
- How to display this meta data (an array) in form of a function (created with a custom write panel)?
- WordPress – using sessions?
- Need To Resize Images Exactly Without Losing Image Details
- Display ACF category image on archive and single template files
- Get slug of current category in functions.php
- Custom image sizes showing in Classic Editor only when upladed directly to post
- How to hide featured images of all posts falling under the same category in wordpress?
- how can I change all wordpress media file url to custom cdn url?
- How to remove font awesome from loading in wp theme
- Display a list of random terms from custom taxonomy with shortcode
- Is it possible to limit number of files a non-admin user can upload via the WordPress media library?
- How to change images url in function.php?
- Change category display name function
- How to replace ACTION url from original wordpress login form?
- WP_Query for Attachments not working as expected
- Header menu aligned right on all pages except for single-post page [closed]
- Display link to category over featured image
- Save_post – Warning: Cannot modify header information
- How to use WP conditional tag in a functions.php with OCEANWP Theme?
- Class parameter in get_avatar args doesn’t get added to output
- Modifying a WordPress Plugin
- Precheck fields when I add a new post
- CF7 select value get to function and reciept value from function
- large image size of 1440×1440 not pulling 2x of 2880×2880 image
- Hide author info in single posts by certain users
- External api call and make global variable for any page visitor enters , page-home, page, single etc
- Remove the ‘category’ url for one category type
- CSS style and app.js not loading
- Custom Function.PHP Code Not Working on One Site
- Adding new Category does not refresh the backoffice
- How do i tweak my wp Post title base on category of the post
- Can You Set A Minimum Image Dimension For Resizing Images?
- blank page with wp_get_attachment
- Parent category as WOOCommerce Categories widget title
- Extend WordPress Audio Widget to accept HLS (.m3u8) URLs
- Shortcode to insert default text and change one word throughout it?
- (Divi): How to make WordPress load images of specific size for Blurb modules on given page with a funciton?
- Images with overlay
- I want to customize the_posts_navigation function by replacing prev and next with images
- how to remove a tag in the_category function
- How Can I Concatenate A String With One Of My Custom Field Value Before Saving The Post?
- Menu and category highlighting for a single post
- i can’t use wordpress functions in ajax loaded php file
- How would I correctly implement a new if statement in a child functions file?
- Woocommerce custom calculation function
- Featured image on archive page based on post type
- WordPress Ajaxifying not working properly
- WordPress function with attribute pass to template
- Will dequeueing in child theme functions.php file prevent Google Fonts from loading?
- Graphic before title – Specific Category
- Printing medium sized image
- True email confirmation for registration (keeping unvalidated users from user table)
- restrict uploaded image size and fixed image display size
- Why am I losing image quality on my site?
- Adding A New Widget to WordPress Disables the Existing Widgets
- require_once() Causing categories and tag pages on dashboard to not refrsh
- How To Show Shortcodes In WordPress Custom Fields?