WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] get rid of p tags in category_description (15 posts)

  1. nathanielstern
    Member
    Posted 6 years ago #

    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!

  2. Samuel Wood (Otto)
    Tech Ninja
    Posted 6 years ago #

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

  3. nathanielstern
    Member
    Posted 6 years ago #

    DELETING AND TRYING AGAIN

  4. nathanielstern
    Member
    Posted 6 years ago #

    NO LUCK

  5. nathanielstern
    Member
    Posted 6 years ago #

    ARRRGH

  6. moshu
    Member
    Posted 6 years ago #

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

    If you can't find it, use http://wordpress.pastebin.ca - the code above is useless...

  7. nathanielstern
    Member
    Posted 6 years ago #

    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.

    anyhow

    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))

  8. nathanielstern
    Member
    Posted 6 years ago #

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

  9. Samuel Wood (Otto)
    Tech Ninja
    Posted 6 years ago #

    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.

  10. nathanielstern
    Member
    Posted 6 years ago #

    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.

  11. nathanielstern
    Member
    Posted 6 years ago #

    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)) ?>
  12. Samuel Wood (Otto)
    Tech Ninja
    Posted 6 years ago #

    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.

  13. nathanielstern
    Member
    Posted 6 years ago #

    worked a charm! thank you!

  14. lokjah
    Member
    Posted 6 years ago #

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

  15. JHouse
    Member
    Posted 6 years ago #

    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.

    Peace.

Topic Closed

This topic has been closed to new replies.

About this Topic