If you’re outside the loop, pass a post ID.
$format = get_post_format( $post_id );
To guard against missing formats, add a default to your template:
$format = get_post_format() ? : 'standard';
Then you can use your same IF statement:
if ( $format == 'link' ) :
Related Posts:
- Shortcode not working with post counter
- subtracting the current post form then whole loop, which is generating all CPT titles
- Set posts of a custom post type to be private by default?
- How can I add dropdown widget/box to admin post page?
- Newer/Older posts links display same posts on every page
- Best way to style first post differently?
- How do I write this SQL statement for Posts written in last 24 hours?
- How to show related posts by category or custom post type?
- Custom post type loops with different page templates
- How to create posts (not post template) to be displayed on projects page?
- Limit Authors to their Own Posts on front-end excluding admins
- Multiple Content Block
- IF statement in a do_shortcode
- How do you output custom code between posts in the loop?
- Why does using WP_Query inside a shortcode in an elementor page cause the arguments for WP_Query to get malformed?
- get_template_part for custom post type content not working
- How would I create a shortcode to display a custom post within a page or regular post?
- Loop on front-page.php
- How to get all posts except for one post from a certain custom post type?
- Notice: Undefined index: suppress_filters
- How i can add ‘N’ page of ‘N’ pages under posts loop?
- I would like to have different styles for my posts based on the content of each post
- List custom taxonomy specific to one custom post type
- Best way to style first post differently?
- Changing default ‘posts’ parameters with register_post_type_args
- Homepage’s content is dependent on the custom field values (set automatically), how do I get homepage to update without manually updating page?
- Allow users to create posts without logging in?
- How to assign classes to all elements?
- Conditional for a Single Post That Belongs to a Category?
- Loop increase number
- Showing custom post type categories in the menu
- How to Make infinite loop of post
- WP_Query with custom post type ID
- WordPress notification if new post published
- display posts of custom post type with custom taxonomy
- Custom wordpress loop
- posts within custom post type all share the same content in the front-end
- displaying content of custom post type
- Posts are not rendering perfectly [closed]
- Template code to split a post and print a custom field?
- Send post changes to set email addresses (not users or subscribers)
- Display post from custom post type
- Use post in multiple places on a page with multiple posts
- The loop does not show users
- Display author box on just certain category posts?
- How to fetch posts that are stored in the different table than (default) wp_posts?
- If/Else child list for Custom Post Type single template within loop?
- redirect after submiting post for review
- Get Posts List of Current Selected Custom Taxonomy in Shortcode
- What is the best way to set the post category (Custom Post Type) automatically based on the one of the tags assigned to the post?
- Pagination not working in custom post type. Help
- SEARCH QUERIES – REVERSE OUTPUT
- How can I group by Taxonomy on Custom Post Type while filtering out based on custom Meta
- Display title of all custom posts from same taxonomy term on a custom post template
- Custom post Query and WordPress Post Query Clash
- When post is Published, insert into custom table a number – custom post type
- Post that populates itself (almost) automatically using data from imported excel file
- How to mark posts as visited
- Work and Display a Custom Post Type as a normal Post
- Only show current category post
- Featured image in custom post is being disabled
- How To Loop Through list with Custom Post Types
- How to create content automatically when a post is published?
- Turn post into simple slideshow
- Pulling in a particular post into a single page based on the post id passed into the code
- Styling first post using Advanced Custom Fields
- the_content() stop images being pulled through
- How to make a non-public post on wordpress approval?
- Where paramaters of a custom function are coming from inside the loop?
- Display all posts starting with given letter?
- wp_pagenavi() with custom wp_query()?
- Make `previous_post_link()` Function Show The Post After Next i.e. Jump A Post
- Allow non-logged in users to see a future post after clicking on a list of future posts
- Update Post Meta for a logged in user
- Displaying Custom Posts on a Page
- Wrapping x posts in html without leaving empty html
- Permalink misbehaving in Custom Post Types
- ACF in wordpress
- Post loop count is not in order
- Display Only Certain Category In a Custom Page Template
- How to inherit field value from parent post into in child / sub post
- hide specific div on single.php [closed]
- How do you output an unknown number of images in a custom post type with desired markup?
- Custom post type’s posts are not showing anywere but in xml sitemap
- How to filter url on post submission?
- Redirect to URL if x number of days passed
- How to controll the Posts post type and general wondering about WP data structure
- Enforcing a rigid reusable template structure for similar posts?
- How to get current post type?
- How to convert Post Object Custom Field into Tags
- How to create an IF statement in the Main Loop for Custom Post Types
- Custom meta fields not showing up in WP_Response Object via custom endpoint
- Duplicate posts in my custom loop
- How to keep a CPT stick to specific position?
- call_user_func_array() error after moving to another server
- Custom post type archive pagination with HTML5Blank theme?
- I want to split this into two functions
- Custom Post Types and 404 Pages
- Add HTML before a specific div?
- Front end post or photo or both