user3173756
user3173756

Reputation: 53

Wordpress custom taxonomy term description html tags

I've looked all over stack overflow and the WP forums and can't find anything from within the last few years that works for this issue.

I've created a custom taxonomy(album category) for a custom post type(album) and I need to display the taxonomy description as html paragraphs, but it just outputs as raw text(which is how it is saved in the database - no html tags at all).

I've tried adding remove_filter( 'term_description', 'wp_kses_data' ); to the functions file, but that does nothing even after re-activating the theme and updating the descriptions.

I could just add a custom field to the taxonomy, but it would be nice to use the existing description field if I could just get it to use html tags.

Upvotes: 1

Views: 3979

Answers (2)

Roberto Poblete
Roberto Poblete

Reputation: 69

delete html tags with strip_tags()

functions.php

function my_custom_single_title() {
    if ( is_tax( array( 'product_cat', 'product_tag' ) ) && 0 === absint( get_query_var( 'paged' ) ) ) {
        $description = wc_format_content( term_description() );
        if ( $description ) {
            echo '<h1>' . strip_tags($description) . '</h1>';
        }
    }
}
remove_action( 'woocommerce_archive_description', 'woocommerce_taxonomy_archive_description', 10 );
add_action( 'woocommerce_archive_description', 'my_custom_single_title', 10 );

Upvotes: 2

Stigwood
Stigwood

Reputation: 131

I am not even qualified enough to be a neophyte, but I did find the following online, and it seems to work and so far not crash my site. No warranties, implied or otherwise. I just feel like I should contribute, given all the help this site has been to me.

remove_filter( 'pre_term_description', 'wp_filter_kses' );
remove_filter( 'pre_link_description', 'wp_filter_kses' );
remove_filter( 'pre_link_notes', 'wp_filter_kses' );
remove_filter( 'term_description', 'wp_kses_data' );

I also think the taxonomy descriptions are generally an underutilized feature, and whatever hacks are available may one day be made into features. I look forward to the downvotes!

Upvotes: 3

Related Questions