Just add the following code in functions.php file of your theme which will add your custom added classes to images when you will insert it into post editor.
function add_image_class($html, $id, $caption, $title, $align, $url, $size, $alt="" ){
$classes = get_post_meta( $id, 'classes', true );
if ( preg_match('/<img.*? class=".*?">/', $html) ) {
$html = preg_replace('/(<img.*? class=".*?)(".*?>)/', '$1 ' . $classes . '$2', $html);
} else {
$html = preg_replace('/(<img.*?)>/', '$1 class="' . $classes . '" >', $html);
}
return $html;
}
add_filter('image_send_to_editor','add_image_class',10,8);
Related Posts:
- How can I append custom data to images in the editor?
- Saving Custom Field in Attachment Window in WordPress 3.5
- Save attachment custom fields on front end
- Can’t display errors in attachment_fields_to_save
- $form_fields from attachment_fields_to_edit returning empty array
- Custom field in media library not saving, selected() function not adding “selected” to select list input type
- Adding fields to attachment – only shows when inserting new attachments
- Adding thumbnails for non-image attachments
- Importing data for advanced custom fields plugin?
- Gutenberg add a custom metabox to default blocks
- Filter post listing by meta value which is a date
- Extra profile field as select box?
- Matching Serialized Arrays with meta_query
- Pre-filling custom fields on New Post
- So much data in postmeta
- Make Custom Field Into A Link On The Front End?
- Show Custom Comment Fields when editing in admin
- How to activate “custom fields” section in WP3
- Why isn’t my code to save custom fields in quick edit working?
- How to oEmbed from custom field, responsive to container size and responsive
- Custom Meta Boxes: Store two values in one repeatable field
- Gutenberg Custom Block
- Custom fields won’t display on my blog page
- How to customize default wordpress editor?
- Up/Down voting system for WordPress
- Custom Meta Field not Working with qTranslate [closed]
- Problem in custom meta boxes
- Loop through two different sets of custom fields
- Add an advert every nth Paragraph
- Undefined index error when saving content on metabox
- Metabox with multiple fields added by user and upload box
- How to update custom user meta field in wp?
- Get all meta keys assigned to a post type
- sort search results by custom fields using dropdown
- WP Custom Fields Metabox Disappears – ACF plugin issue [closed]
- Add conditional custom option to ‘Display name publicly as’ dropdown
- Custom fields not getting saved in the databse when added to the add new user profile page
- I want to send an email when each post is published
- Creating a widget with a number of custom fields
- How to loop through certain custom field values
- add_action and remove_action if custom field exists
- How to Create Dynamic Fields in a Meta Box?
- Set front page option using custom fields?
- Add post meta fields, when creating a post using WordPress’ REST API
- Store array as single, serialized post meta field or many post meta fields?
- Custom Field Values not updating unless I click “Update” twice
- update_post_meta for repeated custom field [closed]
- Can I create a template or doctype for my blog site?
- Custom field, add class to anchor tag
- Custom Metabox additional item
- How to combine custom fields to make one order-able value
- Updating Other User’s Metadata
- get_posts in meta box dropdown not showing latest posts
- Trying to reorder posts by custom field
- Delete custom fields when deleting posts
- Custom Query based on custom field of a single post
- comment meta_query for keys that aren’t yet set
- Link the retrieved custom field values to its respective posts
- Sortable custom field values from all posts on a page template
- How can I use custom properties to set different background on different pages?
- Values entered in a meta box aren’t saved
- change order of images attached to post
- Display meta box dropdown (from custom post type) in the page post type
- How to Make Post Custom Column Editable
- how can I show name and value of Custom Fields together?
- Adding simple (one button) Audio player using Custom Fields?
- tax query between operator like
- Single page WordPress website – custom fields or meta boxes or something else?
- Collect Data from NEXT item while in loop
- Order custom fields alphabetically
- How show post only from after custom date
- Is it possible to compare the current time with a custom “start” and “end date
- Display metabox title for custom fields with values
- Gutenberg add a custom metabox to default blocks
- How to use ACF with javascript to update custom field values?
- Show Custom field value instead of title in WP Menu
- How to add code to custom field to every blog post via php?
- Getting user’s data, by custom field lookup (meta)
- Counting number of images from loop
- Automatically set the_post_thumbnail to Custom Field Value
- Redirecting to an external URL
- Search one custom field?
- Can’t save meta field value if the title not set
- Why is wp_list_pages altering $post->ID of the page?
- how to show this part only in the single post page?
- How to keep sharing stats after creating 301 redirects?
- Custom fields: dropdown values depending on other custom field value
- How do i get a specific user metadata using custom metavalue outside of wordpress?
- Custom search with meta fields
- Creating an If/Else statement using WPAlchemy MetaBox radio boxs
- How to retrive Custom Fields as Values for a Form field
- Use custom field value as href
- Custom fields doesnt work well with any postTAB plugin
- Colecting values from custom field checkboxes and displaying them in the post
- Build Array from Input Fields question
- Custom field for image, not showing image!
- Grouped Custom Meta Fields without plugin
- Google not index my Custom 404 page ?why?
- Dynamically update Custom Fields to display new dates
- save all acf options in one meta_value [closed]