0

To limit title 

add_filter( 'aioseo_title', 'aioseo_filter_title_len' );
function aioseo_filter_title_len( $title ) {
   if ( strlen($title) > 60 ) {
      $title = substr($title, 0, 60);
   $title = rtrim($title, "|"); 
   }
   return $title;
}

To limit description or set description from archive page first post

add_filter( 'aioseo_description', 'aioseo_filter_description' , 10, 1 );
function aioseo_filter_description( $description ) {
  $desc = get_the_archive_description( $before = '', $after = '' );
   if ( is_archive() && empty($desc ) ) {
    global $wp_query;
    $queried_object = $wp_query->get_queried_object();
    $args = array(
        'posts_per_page' => 1,
        'post_type'      => 'post',
        'post_status'    => 'publish'
    );
    if (is_category()) {
        $args['category__in'] = $queried_object->term_id;
    } elseif (is_tag()) {
        $args['tag_id'] = $queried_object->term_id;
    } elseif (is_date()) {
        $args['year'] = get_query_var('year');
        $args['monthnum'] = get_query_var('monthnum');
        $args['day'] = get_query_var('day');
    }
    $first_post = get_posts( $args );
    $excerpt = wp_kses_post( $first_post[0]->post_excerpt );
    $excerpt = substr($excerpt, 0, 157).'...';
    return $excerpt;
  }else if(empty($desc )){
    $description = 'Descriptions';
  }
   return $description;
}

Jagdish Sarma Asked question March 27, 2024
Add a Comment