Support » Themes and Templates » get rid of p tags in category_description

  • Resolved nathanielstern


    Hey wise people.

    I’m using category_description to fill in my title attributes on anchor tags (so when you mouse over a cat, it gives you its description). Worked great in 2.2, but 2.3 seems to add p tags before and after the description – both ugly and not xhtml compliant. Can anyone help me with some code to strip it in the actual function? or elsewhere? Thanks!

Viewing 14 replies - 1 through 14 (of 14 total)
  • Moderator Samuel Wood (Otto)

    (@otto42) Admin

    We’re going to need to see what code you’re using to know what you’re talking about.




    Below it is said clearly: you should put the code between ` (usually top left of your keyboard).

    If you can’t find it, use – the code above is useless…

    yeh, i know i’m doing that and it’s not working… not sure why. i edited several tiems with those, as well as trying html entities.


    basically, without all the right stuff around it, i’ve got
    `a href=”php echo (get_category_link($catid))” title=”php echo (category_description($catid))

    ok, this is just silly. go here and please help.

    Moderator Samuel Wood (Otto)

    (@otto42) Admin

    Your code:
    <a href="<?php echo (get_category_link($catid)) ?>" title="<?php echo (category_description($catid)) ?>"><?php echo $cat_name ?></a>

    So, you’re saying that category_description() is adding <P> tags. Now, in order to figure out why, you’ll need to look in your database and see if those P tags are there to start with. That will tell us if they were added during the save or after the fact when it’s displaying.

    hmmm. I’m hoping I’m doing this right – I went to wp_term_taxonomy and chose one of the descriptions to edit using phpMyAmin, and there were no P tags there. Would they be there were they in the database? If not, then the problem is somewhere else.

    Did I mention I appreciate your help both on this on the other (resolved) issue? I do, thank you.

    but the function does not seem to be the culprit either.

    I replaced the current function from 2.3:

    function category_description($category = 0) {
    	global $cat;
    	if ( !$category )
    		$category = $cat;
    	return get_term_field('description', $category, 'category');

    with the one from wordpress 2.2:

    function category_description($category = 0) {
    	global $cat;
    	if ( !$category )
    		$category = $cat;
    	$category = & get_category($category);
    	return apply_filters('category_description', $category->category_description, $category->cat_ID);

    and i still had the paragraph tag problem (and no errors) when I hit refresh in firefox… where else could the problem be?

    Thanks again. N

    PS my title just calls it in php directly

    <?php echo (category_description($catid)) ?>

    Moderator Samuel Wood (Otto)

    (@otto42) Admin

    I think it’s coming from here, in default-filters.php:

    // Format text area for display.
    $filters = array('term_description');
    foreach ( $filters as $filter ) {
    	add_filter($filter, 'wptexturize');
    	add_filter($filter, 'convert_chars');
    	add_filter($filter, 'wpautop');

    If it is, then a call to remove_filter('term_description','wpautop'); in your theme’s functions.php file will fix it without hacking the core code.

    And switch back to the correct 2.3 code for the category_description() function. Never hack core code when it can be avoided.

    worked a charm! thank you!

    Otto42: Thanks alot for this, I didnt even know I could use my own functions.php in my theme.. thats dope thanks again…

    Otto42, thank you so much. Spent a lot of time trying to figure this out. This post saved me. Thanks to the dude that started it, too.


Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘get rid of p tags in category_description’ is closed to new replies.