You can utilize the WordPress function get_template_part();
Create several template files in your theme directory called content-POST_FORMAT_TYPE.php – Example: content-gallery.php and content-chat.php
if(has_post_format('gallery'))
get_template_part('content', 'gallery');
elseif(has_post_format('chat')
get_template_part('content', 'chat');
else
the_content();
This approach makes your code blocks reusable in multiple templates. Hope this helps you out.
Related Posts:
- Allow HTML in excerpt
- Only get_posts of certain post formats
- static variable loop not working in WordPress
- How to return the_excerpt (without echo)?
- Limit the Excerpt field in WP-Admin in words
- Limit the_excerpt with max of x characters
- Remove at the beginning of the_excerpt() with str_replace
- Automatic Excerpt Not Working
- Trim first 2 words of the exceprt
- How does WP detect format type (and can I make use of this)?
- Extremely slow pageload for long post when using the_content?
- How to change / delete product short description in Woocommerce
- Why does running get_the_excerpt() when generating JSON file take 28 seconds vs. 599 milliseconds without it?
- Excerpt unwanted text “”
- Word Count Function Preventing Permalink Editing
- Custom excerpt function re-factoring
- How to Display a Single Post Excerpt
- How to remove the excerpt in the Dzonia Lite theme
- How to filter posts by post format “standard” from wp-json api?
- Get first URL from post content
- How do I Add HTML to the_excerpt() & the_content() Output?
- How do I use this PHP library to access OpenGraph data in a child theme?
- WordPress add post format support not working
- Mass update excerpt
- How to put “Read more” link in Custom Excerpt inside p tag?
- Error when adding excerpt to the content through functions.php
- trigger html cleanup for all posts
- HTML tags not showing in excerpt
- Query Pages and post excerpts dynamically
- My custom get_the_excerpt() can’t get excerpt by ID
- Adding Meta Tags to a Post using its Tags, Excerpt and content
- Using the_excerpt() on a page
- How to show an entire post content and not also the excerpt?
- stripping tags from excerpt in WordPress is not working
- Automatic excerpt is not shown with the_excerpt() command
- Remove   from the_excerpt
- Shortcodes showing in excerpt despite using strip_shortcodes
- How to remove the space before the ellipsis in excerpt?
- Need help removing […] after excerpt
- Display the video of a post_format Video
- Post class only applying to first excerpt; why?
- Assign Custom classes to every Excerpt
- Wrap posts p tags in div
- Conditional for Post Format
- Problem in replacing the_content with the_excerpt()
- Find and print first entry from WordPress post in custom excerpt?
- Cannot figure out how to add a read more link to a manual excerpt. Please help
- Trying to modify content.php
- How to trim content AND retain HTML?
- How to apply filter
- Add point on excerpt post
- Setting ‘post_format’
- Archive page if else not working for post_excerpt and post_content
- How can I add WordPress Audio Player as featured audio in Audio Blog Posts?
- Creating a function that sanitizes the custom metabox excerpt
- Custom single.php files for different post formats
- How can I add more code to this?
- Merging two excerpt functions to work with conditions
- I can’t seem to get excerpts showing inside get_pages and don’t know why?
- Excerpt all post content Content Same Size without word cutting off
- Remove post image caption from post_excerpt();
- generate excerpt from the part of big text dump that contains keyword
- Using register_activation_hook in classes
- How to create a custom config file and get data using inline JS in a wordpress page
- Replacing the NavWalker dropdown element
- Getting the dropdown menu to redirect to different pages?
- enqueue multiple Google fonts with multiple weights and styles (italic)
- Accessing site’s root from themes folder
- Passing PHP Function Arguments from CLI vs URL
- tracking number field in Woocommerce order [closed]
- Why ajax doesn’t work on certain wordpress hooks and reload the page instead?
- How to add a do_action on refreshing of WP customizer?
- WordPress displaying content from sub pages
- Blob file download problem
- Fatal error: Call to undefined function register_new_user()
- In WordPress, how do I get the number of posts next to single_cat_title(”); in the category.php file?
- Include only posts with meta key “add_in_rss” in RSS Feed
- Need help with Code Correction php+wordpress
- get db values for external js file
- What should I write in the post action of this front end post form?
- Payment field disappears on custom Paypal plugin
- Creating a brand attribute as a variable
- Illegal string offset in PHP function in via Theme Customizer
- Loop for recently (updated_post_meta) posts?
- How to retrieve quantity input field by id in woocommerce
- Handling form actions in WordPress
- PHP code printed into CSS classes
- What syntax is this? “{{post.price}}”
- How to handle the structure of page/taxonomy/post without making wordpress get confused with the url
- Add two or multiple functions in WordPress Post or Page
- Can’t put a hyperlink on Featured Post’s Image
- special characters not supporting in wordpress
- Custom user roles doesn’t apply changes
- get_post_meta is always empty when I use wp_mail
- Too many if’s and else if’s ?? – Must be better way [closed]
- Dynamic Email Handler with ‘header (“Location: …’
- Grabbing value of input field inside of array
- Implement OAuth2 in custom plugin
- Count custom posts type and filter by tag
- Error with PHP 8