Skip to main content
Share Your Experience: Take the 2024 Developer Survey
8 votes

How to query posts of standard post format. For real

Since WordPress 4.1, WP_Tax_Query supports the NOT EXISTS operator for taxonomy queries. As a post has the "Standard" format if and only if it has no specified format, this is now the preferred method ...
engelen's user avatar
  • 3,376
5 votes
Accepted

How to load a different header based on post format?

Say if your have header-video.php used for video post format. Replace get_header(); with get_header(get_post_format()); in your regular singular.php or index.php. If WP can find header-video.php it ...
Z. Zlatev's user avatar
  • 1,149
4 votes

Removing the post format (type) slug

In your last code example, you're returning a wrong type for the post_format_rewrite_base. It should be a string, not an array. However, your idea goes in the right direction. You have to take care ...
David's user avatar
  • 3,275
4 votes

Is There a Difference Between Taxonomies and Categories?

Category is one of the built-in taxonomy in WordPress. So to clear things: taxonomy is a way to group things together. we can create custom taxonomies in WordPress just like built-in ones. For example ...
Anwer AR's user avatar
  • 1,007
3 votes
Accepted

Different markup for each post format

Since you need a specific HTML structure let's keep things clean and do what The Codex suggests - break it into template parts based on the post format. Let's create a subfolder in your theme to store ...
Howdy_McGee's user avatar
  • 20.7k
3 votes

Are content.php and content-single.php the same?

No, content.php and content-single.php are not the same thing. In your example CODE: if (get_post_format() == false) { get_template_part('content', 'single'); } else { get_template_part('...
Fayaz's user avatar
  • 8,917
3 votes
Accepted

Will renaming a `content.php` file cause any problems?

There shouldnt be any issue, dont forget to change the slug in the template part call: get_template_part( 'format', get_post_format() ); the best practice is to have them in their own folder: ...
David Lee's user avatar
  • 3,881
2 votes
Accepted

How does WP detect format type (and can I make use of this)?

This functionality appears to be exclusively a feature of the block editor. It's not especially clever either. All it does is check that if the post has 1 or 2 blocks (and no more), and then maps the ...
Jacob Peattie's user avatar
2 votes
Accepted

Query different number of posts with different formats in one go

This isn’t possible in one query. You can’t set posts per page for individual taxonomy queries. You can either query 12 status or aside posts together: array( 'posts_per_page' => 12, '...
Jacob Peattie's user avatar
1 vote
Accepted

Remove certain post-formats from showing in blog?

It might be possible, but you can not control what the user has in the DB before activating your theme, so you might have to handle "quotes" which are not reviews in any case. In theory you can try ...
Mark Kaplun's user avatar
  • 23.4k
1 vote
Accepted

Can I assign a Folder for Post Formats, without it affecting WordPress' fallback/hierarchical system?

In general, "bad practice" is so common in the wordpress ecosystem, you will have to do something really bad for anyone to actually signal you out for doing it ;) If you are the developer and ...
Mark Kaplun's user avatar
  • 23.4k
1 vote
Accepted

how to retrieve the image title for image Post Format

So first off, I hope you're aware that the quote there is a guideline on how should a post of the image format be displayed to the user, and the thing about the title attribute applies only to posts ...
Sally CJ's user avatar
  • 39.3k
1 vote
Accepted

How to display all posts not in a post_format

It didn't work because your tax query is missing the operator which should be set to NOT IN. So just add it like so: 'tax_query' => array( array( 'taxonomy' => 'post_format', ...
Sally CJ's user avatar
  • 39.3k
1 vote

How to preserve exact formatting when copy pasting from Facebook into WordPress (or elsewhere)?

What you want isn't possible. Why doesn't it work? How Does gmail do it? How does evernote do it? What Can I Do Instead? Why doesn't it work? There is nothing to preserve. When you copy paste the ...
Tom J Nowell's user avatar
  • 59.4k
1 vote
Accepted

display post format text in loop

get_post_format() returns the post format slug for either the current post, when used inside a loop, or a given post, when a WP_Post object or an integer post ID is passed to it as a parameter. So, ...
Antti Koskinen's user avatar
1 vote

Renaming post formats after Gutenberg

The situation with changing strings in the block editor is complicated. There's 2 problems here: The list of post formats used by the block editor (Gutenberg) is not filterable using JavaScript ...
Jacob Peattie's user avatar
1 vote

Get first URL from post content

I think this question might put you in the right direction. In case that link is broken, here's the answer as provided by Jon Fabry in that thread. $post_link = get_the_permalink(); if ( preg_match(...
Faye's user avatar
  • 671
1 vote
Accepted

Is it possible to customize the post according to post format in single.php?

Yes, it is possible. The easiest and very readable way would be to do this like TwentyX themes do - using get_post_format and get_template_part functions. Let's say that your current single.php file ...
Krzysiek Dróżdż's user avatar
1 vote

Is it possible to customize the post according to post format in single.php?

Sure, you can simply grab a class of the post, and then style it with your own CSS. The following code is taken from this page of the WordPress Codex: Post Class This function returns all classes of ...
user3135691's user avatar
1 vote

show a post from a specific post format

In the loop: while ( have_posts() ) : the_post(); get_template_part( 'template-parts/content', get_post_format() ); endwhile; In your theme you should have a directory "template-parts" and have ...
Minh's user avatar
  • 51
1 vote
Accepted

get_template_part() Not Working in Loop

Thinking about my comment...wouldn't it be simplier to say: <section id="content" class="site-content blog-page"> <div class="container"> <?php if ( is_home() || ( ...
rudtek's user avatar
  • 6,121
1 vote

How to add meta box for current post format?

If you want it just for the native post post type, then put this in your functions.php add_action('init', 'my_theme_setup'); function my_theme_setup(){ add_theme_support( 'post-formats', array( '...
Dan.'s user avatar
  • 856
1 vote
Accepted

Set Post Format if find a string in title or post content

You are using $post_id, but you have passed the post ID as $postID. As a result $a is always empty. Even if it weren't empty, there is no PHP function srtpos. It's strpos and you could have more ...
cjbj's user avatar
  • 14.6k
1 vote
Accepted

Removing the post format (type) slug

Excellent answer above, well worth the bounty. For the record, this is what it led to: add_filter( 'post_format_rewrite_rules', 'no_format_base_rewrite_rules' ); function no_format_base_rewrite_rules(...
lucian's user avatar
  • 312
1 vote

Override post-formats in child theme

Make sure that you're not just calling these functions within functions.php, but calling them at the right time with add_action(). Try the following: // in your Child Theme's functions.php // ...
Josh Stabback's user avatar
1 vote

Override post-formats in child theme

It's import to set the priority for your after_setup_theme higher than your parent theme. The default priority is 10. Using the twentysixteen as example, use priority 11 on child themes' '...
cbonomini's user avatar
  • 126
1 vote
Accepted

How to get post attachments in gallery post format template

i had sort out this with function get_post_gallery find the answer if ( ! function_exists( 'flexi_gallery_slideshow' ) ) : /** * Display an optional post read more link * */ function ...
ahmad araj's user avatar
1 vote

Get post format and use it as a CSS class in different spans

Every post has a maximum of one format and one status. To echo the format you need: if (get_post_format($post->ID)) echo '<span class="format-' . get_post_format($post->ID); . '"></...
cjbj's user avatar
  • 14.6k
1 vote

Get post format and use it as a CSS class in different spans

You can also try <span class="<?php echo get_post_format($post->ID); ?>"></span> Additional details available here Edited from here: Well according to the link I provided, ...
bagpipper's user avatar
  • 155
1 vote
Accepted

Display post formats differently on index.php (loop in function)

The best way to do this is get the post format and then use the switch statement, like this: $my_format = get_post_format (); switch ($my_format) { case 'quote': $htmlcontent = ... ; break; ...
cjbj's user avatar
  • 14.6k

Only top scored, non community-wiki answers of a minimum length are eligible