1

When writing out the category description in my theme (on archives and special category listings) for example, there are times I need the description in full html mode and others when I need it returned stripped of any html.

In the code below, I actually need the stripped version of the description, however $category->description returns the full description with all tags, which is rendering my strlen snippet function inoperable depending on where it breaks.

How can I obtain an html stripped version of the description in the loop below?

foreach($categories as $category) {
    echo '<li style="clear:both;">'.get_category_thumbnail($category->term_id, 'thumbnail').'<a style="display:block;margin-top:20px;" href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a>';

        if(strlen($category->description) > 300 ) echo SUBSTR( $category->description,0,STRPOS( $category->description,".",300)+1);
        else echo  $category->description;

1 Answer 1

1

Have you tried something like this?

strip_tags($category->description)

Here the reference page for the strip_tags function

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.