Use get_post_format()
:
function test_filter($content) {
$format = get_post_format();
if ( ! $format )
return $content;
if ( 'audio' === $format )
// do something with audio
if ( 'aside' === $format )
// do something with aside
return "$content <hr>post format: $format";
}
Since the_content()
requires a global $post
object to work, get_post_format()
will always work. It will return FALSE
if the current post type does not support post formats and a post format slug otherwise.
Related Posts:
- Adding a drag and drop re-ordering from a custom post type default list [closed]
- Filter for “get_post_type_archive_link()”
- Remove “Get Shortlink” button in admin of custom post type
- Modifying date filter on admin page for custom post type to link to custom field
- Why is conditionally loading a custom plugin’s code only on a specific custom post type causing the site content to disappear?
- Filter Posts from the Main Query
- Is there any way to get list of all possible filter hooks for all post types?
- sortable columns for multiple custom post types not working
- Catch and display error on save_post action
- Best way to fix bad count on All | Mine | Published
- Store a value in global scope after init hook is fired
- Dynamic page for nav items used as filters
- Adding Information To All Posts Screen
- Filter Content on all Post Types
- Hook only specific post type
- Change CPT Edit Target Link for Admin List
- Filter by custom field in custom post type on admin page
- How can I remove the “Add New” button in my custom post type?
- Calling a Function After New Post Creation for a WordPress Custom Post Type?
- How to remove Filters from post admin page?
- How can I filter posts by post_parent in the admin?
- How do I filter the excerpt metabox description in admin?
- How do I Filter Custom Post Type by Custom Taxonomy in the newest WordPress RESTful API?
- get_query_var() not working in pre_get_posts
- Custom post types vs post formats : future-proofing – is one less “future proof” than another?
- Filter by custom Field for Custom post type Admin Listing
- Admin Post Update Redirection to Posts Screen
- WP Admin default view mode for Custom Post Type
- Remove wpautop from all posts/pages except my custom post type
- How to create notification on frontend using heartbeat api for multiple custom post types
- Remove date and category filters when editing custom post types
- Taxonomy terms with edit/filter link in wp-admin, in the list of custom posts
- Make the ‘all’ filter default instead of ‘mine’ in a custom post type
- Exclude custom function content from certain pages
- Filter get_categories() for taxonomy term in WordPress
- Multiple post types in archives (filter?)
- Unable to filter on field on edit.php page
- Highlight nav menu terms
- Want to filter only parent post in admin area
- Adding posts of custom type into the main feed
- How to register custom post types in a plugin?
- Filters post in admin with dropdown select, custom post type
- Admin List Dynamic Heading
- What is better: Custom Fields vs Custom Taxonomies with Terms for perfomance, scalability and better user experience
- Add $more_link_text parameter to the_excerpt()
- Add html to cpt main page / admin edit.php
- register_taxonomy and register_post_type does not work [closed]
- Filter categories of posts with checkboxes
- WooCommerce product search titles only
- Hooking in to an archive page?
- Add custom column in custom post type edit page
- Setting proper query for multiple custom admin filters
- How to query custom post types posts filtered by multiple custom taxonomies through a form selection
- Genesis filterable portfolio isotope [closed]
- How can I see a list of my Custom Post Types of the last term I was in?
- Posts are duplicating on wp_post_update
- filter custom post type by meta key in dashboard
- How to add a post slug to a url?
- How to filter wp_list_categories output with some custom post type meta query?
- How to Filter custom post type by taxonomy?
- creat filter with wp_query
- A method for ordering mixed dates in search result loop (theory only, no actual code)
- Filter hierarchical custom post type admin page by parent, and include children & grandchildren
- Versioned Custom Post Type (Not the same as revisions)
- Categories filtering in new post
- Is it possible to filter the display name for post formats for display in the Formats meta box?
- Understanding Post Formats/Custom Post types Etc
- Get rid of “trash can” for custom post type
- Custom Meta fields Update hook?
- wp_trash_post action hook with custom post type
- Filter posts by tax (dropdown) and meta value
- How do I amend form data before it is saved for a custom post type
- providing access to post_id or post inside functions.php
- Modifying WP_Title For Custom Post Type
- comments hooks on custom post type
- How does one go about converting custom post type to post format?
- How to recover the post ID earlier in the WP admin hook action “firing” sequence?
- Is possible register two archive pages for single custom post type?
- Ajax Post Filter | Split Taxonomy Into minPrice & maxPrice
- Custom Permalink For Custom Post Type – Working Fine But Broken For Pagination
- Using `set_transient()` when saving a custom post type
- Title and URL Error in Breadcrumb Navigation for Custom Post Types
- Add html tot CPT edit screen – no metabox
- In child theme, add CPT to custom taxonomy registered in parent theme
- Display category filters for custom post type when category is shared by multiple post types
- Changing CPT permalink
- Create Post Types from a XML url (Real Estate website)
- Hook create / update post
- Sort custom post archives by a meta value from a different custom post type?
- Correct way to register custom post type from external php file?
- Keep br tags from stripping
- call a function when insert and update a custom post type
- Add filter button to custom post type in admin area
- Custom Fields as Post Type Options
- do action inside a class is not working
- Dropdown switching subcategories portfolio
- Customizing a plugin function using a hook
- Sorting on Taxonomy in archive page
- When Attempting to Filter Plugin Generated Content Using Filter post_type_link, Permalinks Are Not Modified
- Add Custom Taxonomy Terms as CSS Classes for CPT Posts in an Elementor Loop Item Template