Combining the answer here by @cjcj with the code in this answer, the code that works for me outside the loop, in functions.php is:
// Add ability to check for custom post type outside the loop.
function is_post_type($type){
global $wp_query;
if($type == get_post_type($wp_query->post->ID)) return true;
return false;
}
// Add class to every image in 'wpse' custom post type.
function add_image_class($class){
if ('wpse' == is_post_type()){
$class .= ' additional-class';
}
return $class;
}
add_filter('get_image_tag_class','add_image_class');
Related Posts:
- Image size filtering in Media uploader according to custom post type
- Change post featured image on hover
- Redirect to another page using contact form 7? [closed]
- DIVI Theme customizer changes not applied on existing pages and designs are not shown on the front
- How can I add image sizes for a specific custom post type?
- Add a background image into a post [closed]
- Add html to cpt main page / admin edit.php
- register_taxonomy and register_post_type does not work [closed]
- Custom post type and body_class: Remove “blog” class
- Pre_get_posts filter overwrites all search functionality
- Filter categories of posts with checkboxes
- WooCommerce product search titles only
- List all images from a single post meta value
- Custom Image Thumbnails of Different Sizes
- How to detect filter in URL in Category page?
- Custom query to filter posts that have current post as a taxonomy [closed]
- Why is conditionally loading a custom plugin’s code only on a specific custom post type causing the site content to disappear?
- Is possible add class for last post of Custom Post Type?
- Setting proper query for multiple custom admin filters
- How to query custom post types posts filtered by multiple custom taxonomies through a form selection
- Append date to custom post type url slug
- How to move image thumbnails into custom folder for custom post type
- Genesis filterable portfolio isotope [closed]
- How can I see a list of my Custom Post Types of the last term I was in?
- uploading images to specified directories
- Filtering WP_Query
- Get image post ID in media upload
- Customize my custom taxonomy table in Admin panel
- Link to full size post thumbnail
- Hide editor while keeping add media button in custom post type
- Displaying custom taxonomy in the admin list of a custom post type
- Custom Post Type with image gallery
- Multiple featured sizes / images / excerpts
- How can i add thumbnails images to particular post (using code not admin pannel) in wordpress
- How can I run this code once so that my generated post title doesn’t keep changing on publish/update?
- filter custom post type by meta key in dashboard
- How to Create an Image Upload Box for Custom Posts?
- Categories of custom taxonomy don’t show any posts
- How to add a post slug to a url?
- Add custom image size for custom post type or taxonomy
- WordPress sort search results by custom order
- How to filter wp_list_categories output with some custom post type meta query?
- How to Filter custom post type by taxonomy?
- How to automatically set ‘default image size’ for specific Custom Post Type
- Filter term taxonomy metabox in custom post type
- creat filter with wp_query
- A method for ordering mixed dates in search result loop (theory only, no actual code)
- How can I made custom taxonomies relationship?
- WooCommerce sort products by the actual product width(not the shipping width)
- How to change the post type a theme shows by default?
- filter custom post in rest api with custom function
- How to Create Columns with WordPress and CPTUI display page ?
- Filter hierarchical custom post type admin page by parent, and include children & grandchildren
- Sort and filter custom post type posts by custom taxonomy
- Versioned Custom Post Type (Not the same as revisions)
- Problem: wp_query outputs all images on site
- Loop filtering Custom Post Types and/or Categories
- search suggest – filter post type
- the_content filter on some post types only not working
- Filtering posts list table
- Problems with image size on the server WordPress
- Custom filter function not working with Custom post type
- Filter Posts from the Main Query
- frontend image post uploader
- Categories filtering in new post
- How to use manage_$post_type_posts_columns with underscore in post type?
- Adding custom image sizes and post types to a plugin or to a theme?
- How does the filter post_updated_messages work?
- Search filter triggered & sort by custom post type
- How to order posts of a custom post type by date DESC in dashboard Admin?
- How to handle large number of images in a post?
- How do you get the full size url of an attachment image
- How to add multiple images to a custom post type without plugin [closed]
- How can I add a filter to a particular post format?
- Is there any way to get list of all possible filter hooks for all post types?
- Can I display custom post types in home.php or need page template?
- Create new custom post and post category of same name
- wordpress remove views from action links in a custom post
- How can i link a custom post type thumbnail to intermediate size
- wp_insert_post wrong post type [closed]
- Add custom CSS class to custom post type
- Filter posts by tax (dropdown) and meta value
- Give each post type label a different color?
- Is it possible to add posts and images (auto resize) for custom post types with a script?
- How can I remove filters from custom post types?
- Displaying custom post types as a gallery
- sortable columns for multiple custom post types not working
- I need to add a filter to prepend the term ‘National – ‘ to the post title if the post is tagged to multiple states
- How do I add custom HTML to the content of an archive page’s posts?
- Only show posts with a specific term of an associated taxonomy in a custom post type archive
- REST filters only firing when I have a param set
- How do you output an unknown number of images in a custom post type with desired markup?
- copy images from custom field to another custom field
- Problem with Apply Filters on URL in meta box filed of custom port type
- how to retain the ability to modify the post slug after applying a post_type_link filter?
- Trying to add a class to post links
- How do I show a link or ‘Read More’ button on a custom field excerpt when it is less than the word limit
- One Site. One Theme. Multiple Stylesheets without plugins?
- Using Image Sizes for Custom Post Types outside the Loop
- link featured image to external link