Reviewing filters for v3.1 update compatibility
-
Hello Sybre
I note that in your foreword on v3.1 you offered to review code for filters and adjustments for TSF to ensure compatibility with your new update.
Thank you very much for offering that valuable assistance.
The filters that I am currently using are as follows:
1. Remove Site Name From Selected Shop Parent Category Titles
add_filter( 'the_seo_framework_add_blogname_to_title', function( $add = true ) { // List of IDs to remove the blogname from. $ids = array( 262, 268, 207, 235 ); if ( in_array( the_seo_framework()->get_the_real_ID(), $ids ) ) { $add = false; } return $add; } );
With regard to this filter, please note that I need to be able to implement it on selected categories identified by ID. A blanket removal of the site name from all shop category titles is not suitable.
2. Activate Shortcode Rendering in Titles
add_filter( 'the_seo_framework_do_shortcodes_in_title', '__return_true' );
3. Auto Year, Month and Year-Month Shortcodes
add_filter( 'the_seo_framework_title_from_custom_field', function( $title ) { return $title ? do_shortcode( $title ) : $title; } ); // Register [year] shortcode. add_shortcode( 'year', function() { return esc_html( date( 'Y' ) ); } ); // Register [month] shortcode. add_shortcode( 'month', function() { return esc_html( date( 'F' ) ); } ); // Register [year-month] shortcode. add_shortcode( 'year-month', function() { return esc_html( date( 'Y F' ) ); // insert M = Jan F= January } );
4. Add Product Count to Shop Parent Category Titles
// [cmulti] = total products // [cmulti term='INSERT PAGE ID NO'] = count for specific category function custom_multi_shortcode( $atts, $content = null ) { // Shortcode attributes $atts = shortcode_atts( array( 'term' => '' ), $atts, 'cmulti' ); // 1 - Total product count if ( empty($atts['term']) ): $count_posts = wp_count_posts( 'product' ); return esc_html($count_posts->publish); // 2 - Count for specific category else: $query = new WP_Query( array( 'tax_query' => array( array( 'taxonomy' => 'product_cat', 'field' => 'id', 'terms' => (int) $atts['term'], // Replace with the parent category ID 'include_children' => true, ), ), 'nopaging' => true, 'fields' => 'ids', ) ); return esc_html( $query->post_count ); endif; } add_shortcode( 'cmulti', 'custom_multi_shortcode' );
Thanks again for you help.
Kind Regards
Max
- The topic ‘Reviewing filters for v3.1 update compatibility’ is closed to new replies.