Autogenerator of Description meta tags in ad categories

This snippet will automatically fill in the meta description in categories that do not have a description in the site admin panel.

function add_meta_description_to_listing_category() {
    if ( is_tax( 'hp_listing_category' ) ) {
        $term = get_queried_object();

        if ( empty( $term->description ) ) {
            $category_name = $term->name;
            $meta_description = ' ' . $category_name . ' | Your text for meta description';

            echo '<meta name="description" content="' . esc_attr( $meta_description ) . '" />';
add_action( 'wp_head', 'add_meta_description_to_listing_category' );
1 Like


Thank you for your solution, it will be useful for our community. Also, you can join our Experts program. If you pass the test, we’ll add you to the list of experts, and our customers will be able to contact you if they need some help with their websites Experts | HivePress

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.