WordPress Post Formats Tutorial Updated 2021

WordPress Post Formats Tutorial

WordPress Post Formats Tutorial Updated 2021



Today we are going to explore WordPress Post formats. So in wordpress if you want to show some custom content looking bit different in style than usual posts then you can use post-formats, It will allow you to show highlighted content or image gallery or link to some website with styles etc.





There are a couple of post formats we can use in WordPress.



  1. Standard – This is the default post format (Selected by default)
  2. Aside – A note-like post we can style it with or without a title.
  3. Gallery – Gallery of images.
  4. Link – Link to another site (You can set the site link goes to)
  5. Image – An image or photograph we can add
  6. Quote – A quotation.
  7. Status – Twitter-like short status update
  8. Video – Post containing video
  9. Audio – Audio file.
  10. Chat – A chat transcript

We are going to add a few of these post formats into our custom theme.





So let’s get started.



To add post format in any theme we can go into the “functions.php” file and there we can add this code to enable post-formats.





// add Features

function addFeaturesInTheme(){
    // Add post formats support
    add_theme_support('post-formats',array('aside','gallery','link'));
}

// enabling feature after theme setup
add_action('after_setup_theme','addFeaturesInTheme');

Once you have this code saved you should see post formats in your add/edit post page.



Here we have gallery post-format selected

Now add images in your gallery after selecting “Gallery” as given in the image. and in theme, you need to create a “content-gallery.php” file.





For more clarity check this



WordPress Post-formats complete guide step by step

Notice here we are creating file “content-gallery”, As we are dealing with gallery post so we added “gallery” in file name. But content came from “get_template_part” function. Have a look





if(have_posts()):
                while(have_posts()): the_post();
                    get_template_part('content',get_post_format());             
                endwhile;
            endif;

So we are using loop content from the “content” file. If you are not aware of “get_template_part” then check this



WordPress get template part tutorial step by step

Mainly our gallery will be printed using the “get_post_format” WordPress function. as given in code above.