I ran into a little problem today: some piece of code, somewhere in the bowls of WordPress, or perhaps in my theme, was adding extra <p> tags to my category descriptions. This meant that when I retrieved a category description using the category_description() function, the result was wrapped in paragraph tags.
Normally, this would be ok, or even desirable, if I were using the description text somewhere in the body of a page. Today, however, I wanted to use each category description as the title attribute of a link. If you hover your mouse over the boxy category links across the header, “Technology” for example, you’ll see what I mean. Extra, visible <p> tags would have looked ugly to the user, and the resulting code would not be valid. So, I needed to trim off those paragraph tags.
I found a quick solution in a WordPress support forum post: simply add remove_filter('term_description','wpautop'); to the functions.php file in your theme. I added this call very close to the beginning of the file, right after a require_once(), just inside the <?php tag.
Worked like a charm.
Tags: Wordpress4 Comments


4 responses so far ↓
Hey, Thanks for this, I followed a little on the Forum, but didn’t stick around and then found this post. I used it and refferenced it on my blog here:
http://theportfolio.ofmichaelanderson.com/rd/categories-with-descriptions-no-plugins-needed/
Thanks again, it worked like a champ! Also the form is above, not below.
“Today, however, I wanted to use each category description as the title attribute of a link” – how did you end up doing that? I’d like to do that as well (also this little fix was very helpful)
Years later, still a helpful post for the exact same thing I ran into today. Thanks a bunch, worked perfectly!
Thanks for this solution. I just recently ran into this and needed to get rid of the extra paragraph tags in the description. I am doing something similar on a clients website and those extra paragraph tags were a real bother.