HomeUncategorizedHow To Create WordPress Post Formats

There’s a lot going on here, so I’m going to step through this code, bit by bit, so you can see how it is set up.

<article id="post-" >

This is just some basic code to start off our HTML structure. We are adding the post_class function to get proper classes (including .format-link) along with container and header elements. This is taken directly from the default template, which is the “content.php” file in my main theme folder. You can edit this part to match your theme however you wish.


This section uses the “is_single” conditional tag to check if we are on a single post page or not. If we are, we render the title in an h1 tag, which is the default. Of course, users shouldn’t be visiting this page because we are linking away from it, but it’s a good fallback.


<a href="">

This is an external link and will take you to a new page.

Here is where the real magic if happening. We are using the get_my_url function we created earlier, to store the first link from our post in the $myLink variable. Then, in an h2 tag, we are echoing out that link in an a element. So, instead of linking to a post, link formats will link to the first external link of the post (in our case, https://elegantthemes.com).

Next, we are simply adding the title to be the text of our link. Remember, we added the link icon in our CSS which will be automatically added before each of our titles. Finally, we are adding a bit of text that tells our users that they are about to be directed to a new page.


We are ending our post with the same markup from the default template, to ensure that the post renders like normal on single pages, and all of our HTML elements are closed.

In the end, we end up with a different look for link posts on our homepage.


This is, of course, just the beginning. There is a lot that can be done with post format templates to edit and modify the output of your posts based on post formats, allowing for a full range of content. If you’re interested in finding out more about how this works, I’d recommend diving into the content templates to see how they work or visiting the WordPress codex entry on Post Formats.


The last trick I’ll share with you is how to organize your posts according to post format. WordPress comes with a handy function, get_post_format_link that allows you to link to a page that only includes posts from a specific post format. To use it, simply use this function in any template file.

This will provide a link to a list of “Aside” posts. Switch out the name of the post format to match which post format you are linking to. This can be useful in navigation, or grouping together posts. If your blog makes heavy use of post formats, it can be a great way to organize content.

Final Thoughts

There is a lot of discussion about post formats right now, and their future is a bit up in the air. But if you’re running a content-driven blog, they can be an extremely useful tool and can add some solid extra functionality to your posts. Elegant Themes themes feature post formats quite a bit, and you can explore almost any of them to get an idea of how it all works. The best way to get started is to simply dive in!

The post How To Create WordPress Post Formats appeared first on Elegant Themes Blog.


How To Create WordPress Post Formats — No Comments

Leave a Reply

HTML tags allowed in your comment: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Website Design by Larry Bartley, Image1Plus