• Skip to main content
  • Skip to primary sidebar

Victor Font Consulting Group, LLC

The DEX Intranet Specialists

  • Home
  • Care Plans
    • Care Articles
    • Optional Subscriptions
  • Consultations
  • Products
    • Code Snippets
    • Public GitHub Repositories
    • Gist Snippets
    • Pastebin Snippets (Free)
    • Free Plugins
  • FAQs
  • Support
    • Graphic Design
  • Contact
    • Speakers
    • Portfolio
  • Resources
    • Free WordPress Video Training
    • Tutorials
    • Articles
    • Cybersecurity
    • EU Referral Network

Remove Wpautop for Specific Post Formats

September 19, 2015 By Victor M. Font Jr.

WordPress Add New Post public domain image courtesy of pixabay.com

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.

  • 7shares
  • Facebook0
  • Twitter0
  • Pinterest0
  • LinkedIn6
  • Print
  • SMS0

Filed Under: Code Snippet, Genesis, Programming, WordPress Tagged With: Code Snippet, Genesis, Programming, WordPress

About Victor M. Font Jr.

Victor M. Font Jr. is an award winning author, entrepreneur, and Senior IT Executive. A Founding Board Member of the North Carolina Executive Roundtable, he has served on the Board of Advisors, of the North Carolina Technology Association, the International Institute of Business Analysis, Association of Information Technology Professionals, Toastmasters International, and the North Carolina Commission for Mental Health, Developmental Disabilities, and Substance Abuse Services. He is author of several books including The Ultimate Guide to the SDLC and Winning With WordPress Basics, and Cybersecurity.

Primary Sidebar

Shopping Cart

Books

  • Winning With WordPress Basics 2nd Edition Winning With WordPress Basics 2nd Edition $19.95
  • Ultimate Guide to the SDLC front cover The Ultimate Guide to the SDLC
    Rated 5.00 out of 5
    $74.95

Recent Articles

  • Modern Scam Defense: How Consumers and Businesses Can Recognize and Stop Email, Phone, and Text Fraud
  • How to Write a PRD So Dense It’s Technically a Novel
  • Top 5 Plugin Names That Scare Our Legal Department
  • When Agile Meets Our 3-Year Waterfall Roadmap: A Love Story
  • Why Our Enterprise Needs 27 Stakeholders to Approve a Button Color Change

Top 10 Article Categories

Best Practice Code Snippet Computers and Internet Genesis How To Leadership Programming Servant Leadership Tutorial WordPress

 
We only use analytical cookies on our website that allow us to recognize and count the number of visitors, but they do not identify you individually. They help us to improve the way our website works. By clicking Accept you, agree to cookies being used in accordance with our Cookie Policy.