• Resolved traquila

    (@traquila)


    Hello Rank Math SEO team. For a long time, I have been using HTML tags for SEO in the category descriptions of my WooCommerce products, and today, when I looked at the source code of the product category page, the 300-word article I wrote appeared in the description section with HTML tags.

    View post on imgur.com

    I have allowed the use of HTML in product category descriptions. In this way, whatever I enter in that section appears as an article under my product category page.

    View post on imgur.com

    View post on imgur.com

    How can I get them removed this way?

    View post on imgur.com

    How can I do this with the functions.php file?

    add_filter( 'rank_math/sitemap/url', function( $output, $url ) {
    $lang = '<xhtml:link rel="alternate" hreflang="de-ch" href="' . htmlspecialchars( $url['loc'] ) . '" />';
    $lang = str_repeat( "\t", 1 ) . $lang . "\n";
    $output = str_replace( '</url>', $lang . '</url>', $output );

    return $output;
    }, 10, 2 );

    I want the length of product category descriptions to be 150 characters and the html characters to be deleted.

    • This topic was modified 1 year, 3 months ago by Yui.
    • This topic was modified 1 year, 3 months ago by traquila.
    • This topic was modified 1 year, 3 months ago by traquila.
Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Support Rank Math Support

    (@rankmathsupport)

    Hello @traquila,
     
    Thank you for contacting Rank Math support.
     
    You can use this filter to register a new variable to get a long description of your product category, removing all the HTML tags and limiting the words to 150:
     
    add_action( 'rank_math/vars/register_extra_replacements', function() {
    rank_math_register_var_replacement(
    'woo_full_desc',
    [
    'name' => esc_html__( 'Woo Full Desc.', 'rank-math' ),
    'description' => esc_html__( 'Woo Full Description…', 'rank-math' ),
    'variable' => 'woo_full_desc',
    'example' => woo_full_desc_callback(),
    ],
    'woo_full_desc_callback'
    );
    } );
     
    function woo_full_desc_callback() {
    global $post;
    if ( empty( $post ) ) {
    return 'Product Description';
    }
    return mb_strimwidth( wp_strip_all_tags( $post->post_content ), 150, '…', 'UTF-8' );
    }
     
    Once done, you can use the %woo_full_desc% variable in the SEO description field.
     
    Here’s how you can add a filter/hook to your WordPress site:
    https://rankmath.com/kb/wordpress-hooks-actions-filters/
     
    Hope that helps.

    Thread Starter traquila

    (@traquila)

    @rankmathsupport

    You are truly amazing. You’ve given me another reason to recommend the Rankmath plugin to my clients.

    The 150 character limit gave me an error, but I solved it with such a code correction.

    function woo_full_desc_callback() {
    global $post;


    if ( empty( $post ) ) {
    return 'Product Description';
    }


    $full_description = get_the_content( null, false, $post );


    $short_description = mb_substr( $full_description, 0, 150, 'UTF-8' ) . '…';

    return $short_description;
    }

    How can I print the description of the relevant category here?

    This shows the description of the first product in that category

    • This reply was modified 1 year, 3 months ago by traquila.
    • This reply was modified 1 year, 3 months ago by traquila.
    Plugin Support Rank Math Support

    (@rankmathsupport)

    Hello @traquila,

    The filter we shared before was to create a variable to get the product description. Please replace it with the following filter:

    add_action('rank_math/vars/register_extra_replacements', function () {
    rank_math_register_var_replacement(
    'term_desc',
    [
    'name' => esc_html__('Term description', 'rank-math'),
    'description' => esc_html__('Description of current term', 'rank-math'),
    'variable' => 'term_desc',
    'example' => term_desc_callback(),
    ],
    'term_desc_callback'
    );
    });
    function term_desc_callback()
    {
    $term = get_queried_object_id();
    $desc = term_description($term);
    return mb_substr( $desc, 0, 150, 'UTF-8' ) . '…';
    }

    Once done, you can use the %term_desc% variable to get the correct description.

    Hope that helps and please do not hesitate to let us know if you need our assistance with anything else.

    Thread Starter traquila

    (@traquila)

    @rankmathsupport It really worked thank you. God bless you.

    Plugin Support Rank Math Support

    (@rankmathsupport)

    Hi @traquila,

    We are super happy that this resolved your issue. If you have any other questions in the future, know that we are here to help you.

    If it isn’t too much to ask for – would you mind leaving us a review here?
    https://wordpress.org/support/plugin/seo-by-rank-math/reviews/#new-post
    https://www.trustpilot.com/evaluate/www.rankmath.com

    It only takes a few minutes, but it makes a huge difference.

    It would mean so much to us and would go a long way.

    Thank you.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Category Archive Description’ is closed to new replies.