Because the credit data is saved in the attachment’s post meta, not the main post:
$credit = get_post_meta( $post->ID /* Wrong ID! */, 'credit', true );
Instead you need to catch the ID of the inserted image:
function attach_image_credit( $images ) {
$return = $images[0];
// Get the image ID from the unique class added by insert to editor: "wp-image-ID"
if ( preg_match( '/wp-image-([0-9]+)/', $return, $match ) ) {
if ( $credit = get_post_meta( $match[1] /* Captured image ID */, 'credit', true ) )
$return .= $credit;
}
return $return;
}
Related Posts:
- apply_filters(‘the_content’, $content) vs do_shortcode($content)
- the_content and is_main_query
- How to appending to the_content using add_filter with custom post type?
- How to hook a filter to catch get_post_meta when alternate a custom field output?
- How to use update_{$meta_type}_metadata filter to modify meta value
- How to wrap an element around an iframe or embed in content automatically?
- WordPress Internal @ Mentions
- Where to hook into post content?
- Insert Custom HTML After Shortcode
- Add whitespace between Chinese and other letters
- Hook added to the_content seems to be called multiple times
- Get excerpt from $post->post_content
- Add Class to Specific Paragraph of the_content()
- add_filter for specific pages
- What params are available with the_content filter?
- Using variable from one filter in another filter
- apply_filters(‘the_content’, $content) alternative
- What effect does the_content filter have on performance?
- Add post/page ID to inserted links within the_content
- How to apply content filter permanently?
- How to prepend text to the_content, but after img/shortcode
- Format content value from DB outside of WordPress filters
- Is it possible to Hook/Filters Attachment Creation?
- What is the filter hook for custom fields content?
- How can I add a fifth option to the alignment picker?
- How to filter into post meta data before saving
- What functions are included in apply_filter(‘the_content’)
- Filter Gutenberg Blocks Content
- Return array of images after content
- Nested calls the the_content filter
- Explanation for remove_filter used in the below code [closed]
- Add a header before fields added with the attachment_fields_to_edit() filter
- Filter list by a unique meta value dilemma
- Replacing with(out) regex link to attachment by links to files
- How to remove get_post_metadata using remove_filter inside a class?
- Editing
- the_content filter – checking the post
- Apply the_content filter, but prevent other hooked actions
- Wrap h1-h6 in a div
- Sorting and limitation with pre_get_posts
- How to change the order (priority) of registered filters (or actions) (e.g. for the_content)?
- Function the_content not working
- Can’t check if a post has thumbnail adding filter to get_post_metadata()
- ‘the_content’ filter removing html tags from post content
- add_filter(‘the_content’, ‘…’) stops pagination from working
- Post Content, Special Characters and Filters
- Filter on the_content doesn’t update the content being searched via register_rest_route
- How to hide Ads in between posts on AMP? [closed]
- Add content as soon starts
- Remove Content Filter
- wp_upload_bits Upload Specific Sizes Only
- tag removed not using a filter
- Replace audio links with jplayer using the_content filter
- Custom wp_query time filter on meta_value
- Add a div of content within the_content after a certain block
- How do you get specific tags from the_content?
- Can i use multiple ‘the_content’ filters?
- get_post() containing gallery is outputting an unmatched closing div at the end of the content
- Load Posts’ individual body content on index starting at char 200 of each post
- Excerpt is being added above the content, but it should be after it
- What is the earliest hook to modify post content?
- Filter content for get_the_content()
- Filter for author list in gutenberg core editor
- Filter posts by meta data using custom query
- Why is overwriting $GLOBALS killing the_content()?
- add_filter the_content doesn’t work
- How can I get the default content of WordPress post?
- Email Obfuscation: Is antispambot() Acceptable? [closed]
- alternative to the_content filter
- add_filter to the_content after apply_filters
- Excluding posts by meta, and also keeping posts without the meta
- How to stop DOMDocument destroying embeds?
- Scanning for custom embed and prefetching
- the_content getting current page content instead specified ID
- get_post() with filters applied
- How to wrap pattern-matches from the_content in [wiki]-shortcode tags
- Set Microsoft Word links to open in new window/tab
- How do I isolate the reason a wordpress filter is not running?
- Custom permalink for attachment
- Overriding Generated Attachment Post URL
- the_content filter not working when Jetpack activated. Any idea?
- Apply a filter str_replace on specific caracters array in the_content()
- How to add more than one custom metadata as filter on the post list page?
- changing size image within the content
- Hide H1 Title using the_title filter
- Can’t get content of all (19) posts – Incomplete Chunked Encoding
- Add class to all parent elements inside the_content
- filter on the_content stopped working when I updated to WP 3.6.1
- Adding an orderby filter, casting postmeta with multiple keys
- post->post_content filter
- Replace image scr with it’s surrounding href
- After adding filter to plugin’s code, post’s content doesn’t display
- Limit total tags in the_content
- Can I add custom meta for each image uploaded via media-upload.php?
- Filter oembeds tags to modify iframe attributes
- Filter taxonomy admin pagination
- Create Search Form to Filter Through Terms
- Upload restrictions – upload_mimes – filter: Adding multiple MIMEs for a single extension and adding multiple extensions for a single MIME type?
- Modify WordPress Page Title ()
- WordPress Attachments vs Post Meta