Second description field for category pages
-
I’ve found a code that allows me to add a second description field for a category page. That text is then displayed underneath the products.
However, when typing text into the box when editing, it seems that Yoast SEO does not recognize/count the words in the second box
I found the code here: https://www.businessbloomer.com/woocommerce-add-a-second-content-box-product-category-pages/
-
We understand that our Yoast SEO plugin is having difficulties detecting content from the custom field as a second description box.
The Yoast SEO for WordPress plugin only analyzes the default WordPress content areas like the title, URL and the main WordPress content editor. If you are adding your content through other plugin or theme content boxes, Yoast SEO for WordPress might not be able to detect it by default.
We provide plugin and theme developers with an API that they can use to pass their content to our page analysis. So, if you are using a plugin or theme that doesn’t send their content to our page analysis, please reach out to the developer and ask them about adding the functionality to their code. This KB article will help them with the implementation – Can I add data to the page analysis?
Would it be possible to write an alternative to the code so that the 2nd description box is actually placed above the products and the 1st box is placed underneath the products – that would do the trick for me
/** * @snippet Add new textarea to Product Category Pages - WooCommerce * @how-to Get CustomizeWoo.com FREE * @author Rodolfo Melogli * @compatible WooCommerce 5 * @donate $9 https://businessbloomer.com/bloomer-armada/ */ // --------------- // 1. Display field on "Add new product category" admin page add_action( 'product_cat_add_form_fields', 'bbloomer_wp_editor_add', 10, 2 ); function bbloomer_wp_editor_add() { ?> <div class="form-field"> <label for="seconddesc"><?php echo __( 'Second Description', 'woocommerce' ); ?></label> <?php $settings = array( 'textarea_name' => 'seconddesc', 'quicktags' => array( 'buttons' => 'em,strong,link' ), 'tinymce' => array( 'theme_advanced_buttons1' => 'bold,italic,strikethrough,separator,bullist,numlist,separator,blockquote,separator,justifyleft,justifycenter,justifyright,separator,link,unlink,separator,undo,redo,separator', 'theme_advanced_buttons2' => '', ), 'editor_css' => '<style>#wp-excerpt-editor-container .wp-editor-area{height:175px; width:100%;}</style>', ); wp_editor( '', 'seconddesc', $settings ); ?> <p class="description"><?php echo __( 'This is the description that goes BELOW products on the category page', 'woocommerce' ); ?></p> </div> <?php } // --------------- // 2. Display field on "Edit product category" admin page add_action( 'product_cat_edit_form_fields', 'bbloomer_wp_editor_edit', 10, 2 ); function bbloomer_wp_editor_edit( $term ) { $second_desc = htmlspecialchars_decode( get_woocommerce_term_meta( $term->term_id, 'seconddesc', true ) ); ?> <tr class="form-field"> <th scope="row" valign="top"><label for="second-desc"><?php echo __( 'Second Description', 'woocommerce' ); ?></label></th> <td> <?php $settings = array( 'textarea_name' => 'seconddesc', 'quicktags' => array( 'buttons' => 'em,strong,link' ), 'tinymce' => array( 'theme_advanced_buttons1' => 'bold,italic,strikethrough,separator,bullist,numlist,separator,blockquote,separator,justifyleft,justifycenter,justifyright,separator,link,unlink,separator,undo,redo,separator', 'theme_advanced_buttons2' => '', ), 'editor_css' => '<style>#wp-excerpt-editor-container .wp-editor-area{height:175px; width:100%;}</style>', ); wp_editor( $second_desc, 'seconddesc', $settings ); ?> <p class="description"><?php echo __( 'This is the description that goes BELOW products on the category page', 'woocommerce' ); ?></p> </td> </tr> <?php } // --------------- // 3. Save field @ admin page add_action( 'edit_term', 'bbloomer_save_wp_editor', 10, 3 ); add_action( 'created_term', 'bbloomer_save_wp_editor', 10, 3 ); function bbloomer_save_wp_editor( $term_id, $tt_id = '', $taxonomy = '' ) { if ( isset( $_POST['seconddesc'] ) && 'product_cat' === $taxonomy ) { update_woocommerce_term_meta( $term_id, 'seconddesc', esc_attr( $_POST['seconddesc'] ) ); } } // --------------- // 4. Display field under products @ Product Category pages add_action( 'woocommerce_after_shop_loop', 'bbloomer_display_wp_editor_content', 5 ); function bbloomer_display_wp_editor_content() { if ( is_product_taxonomy() ) { $term = get_queried_object(); if ( $term && ! empty( get_woocommerce_term_meta( $term->term_id, 'seconddesc', true ) ) ) { echo '<p class="term-description">' . wc_format_content( htmlspecialchars_decode( get_woocommerce_term_meta( $term->term_id, 'seconddesc', true ) ) ) . '</p>'; } } }
Please note that the positioning of the boxes won’t fix the SEO analysis. You need to add the functionality of the code as discussed before.
Providing programming support is beyond the scope of what our team can provide. And even though we cannot be of any assistance, you’re completely free to change anything in the plugin to better suit your needs.
And though we can’t help with specifically, someone from the community might help you when visiting this thread. So, we’ll leave the thread open for a week.
Can I assume that the search engines will scan and pick up the text in the 2nd description box regardless, but that Yoast SEO just isn’t capable of reading the text at the current moment?
Hi @hyldahl82
While the Yoast SEO plugin is compatible with the default WordPress block and classic editor, and some page builders (such as Elementor), for other third-party page builders and custom theme or content boxes, the content analysis might be unable to detect and parse the content as these build on top of the standard editor. You can learn more about it here – https://yoast.com/help/is-the-plugin-compatible-with-xyz-visual-page-builder/
Your assumption is correct. The bots and crawlers will still be able to pick up and parse the content on your page. It’s just the limitation of the content analysis in the Yoast SEO plugin that is unable to detect the content outside of the default WordPress editor (unless you modify the code as mentioned here).
We are going ahead and marking this issue as resolved due to inactivity. If you require any further assistance please create a new issue.
- The topic ‘Second description field for category pages’ is closed to new replies.