A Genesis Framework user recently asked this question on the Studio Press forum:
I am trying to remove wpautop for my link post format only. I am using the below function/hook but it removes wpautop for all post types on the main page. On single post pages it seems to work correctly, p tags are removed for link format posts but remain for standard posts. Is there a reason the condition is not recognized on the main blog page? Or am I hooking this in the wrong place? Any advice would be much appreciated.
Okay, let's break this down:
What is Wpautop?
The WordPress wpautop() function can be found in wp-includes/formatting.php. WordPress uses this function to filter your post and page content and excerpts to change double line-breaks in the text into HTML paragraph tags (<p>â¦</p>).
What are Post Formats?
Post formats have been a WordPress feature since Version 3.1. Post formats are enabled in themes to provide a consistent way to designate content types so developers can customize CSS styling rules for these various post formats. The WordPress codex defines nine (9) post formats that can be enabled on your site:
- aside - Typically styled without a title. Similar to a Facebook note update.
- gallery - A gallery of images. Post will likely contain a gallery shortcode and will have image attachments.
- link - A link to another site. Themes may wish to use the first <a href=ââ> tag in the post content as the external link for that post. An alternative approach could be if the post consists only of a URL, then that will be the URL and the title (post_title) will be the name attached to the anchor for it.
- image - A single image. The first <img /> tag in the post could be considered the image. Alternatively, if the post consists only of a URL, that will be the image URL and the title of the post (post_title) will be the title attribute for the image.
- quote - A quotation. Probably will contain a blockquote holding the quote content. Alternatively, the quote may be just the content, with the source/author being the title.
- status - A short status update, similar to a Twitter status update.
- video - A single video or video playlist. The first <video /> tag or object/embed in the post content could be considered the video. Alternatively, if the post consists only of a URL, that will be the video URL. May also contain the video as an attachment to the post, if video support is enabled on the blog (like via a plugin).
- audio - An audio file or playlist. Could be used for Podcasting.
- chat - A chat transcript.
What is has_post_format($format,$post_id)?
The has_post_format function is one of the many that WordPress has built-in that allows developers to work more efficiently with post formats. This particular function returns a boolean (true/false) value if the targeted post format(s) are assigned to a specific post. This function generally works in the WordPress loop. In the case of the Genesis Framework, it would normally be executed in a custom version of the Genesis Loop.
The reason why the code above didn't work for the original poster, is because he or she is attempting to execute outside of the standard loop in the Genesis Before Loop action. When executed outside of a loop, the has_post_format function must be served a post ID. The following code is untested, but includes the correct method for including a post ID.
