Using get_post_format_strings() in WordPress

get post format strings wordpress
18 April 2025

Introduction to get_post_format_strings()



In the world of WordPress, one of the very useful tools is the function get_post_format_strings(). This function helps us display different post formats on a WordPress site elegantly. Post formats can include content types such as 'text', 'image', 'video', and others, allowing us to display our content in a more organized manner.



You can easily retrieve format names along with descriptions defined for each format using this function. For example, if you have a post with an image format, by using this function, you can obtain the format name and its description to utilize it in your site design.



It is good to know that WordPress previously defined several post formats and you can create new formats as well. This function gives you the ability to seamlessly work with these formats in your theme templates and files.



Now, let's take a look at sample code for using this function and see how we can utilize it practically. After invoking this function, you can apply your own design codes to the formats that you have defined, enhancing the user experience.



Additionally, by using this function, you have the option to aesthetically utilize these formats in beautiful designs that you create, providing a better user experience.


Sample Code


<?php
$format_strings = get_post_format_strings();
foreach ($format_strings as $format => $string) {
echo <strong>$string</strong>; // Display format description
}
?>

Code Explanation


$format_strings = get_post_format_strings();

This line invokes the function get_post_format_strings() and stores all the post formats in a variable called $format_strings.


foreach ($format_strings as $format => $string) {

In this line, a foreach loop is defined that allows us to iterate over each format in the array $format_strings.


echo <strong>$string</strong>;

In this line, the description of each format is displayed with the <strong> tag so that it appears bold.


}

This line marks the end of the foreach loop.


FAQ

?

How can I create new post formats?

?

Can I customize post formats for each content type?

?

How can I retrieve the current post format?