Hi all I have a site in wordpress and I want to limit the character of the preview post different from default for example obnly 5 characters.
This is the piece of my content-category.php
<div class="entry-content">
<?php
$excerpt = get_the_excerpt();
if ( $use_excerpt == 'Content' ) {
the_content('<a style="margin-left: 5px;text-transform: uppercase;display: inline-block;" href="'. get_permalink($post->ID) . '"> '. __( 'Leggi Tutto' , 'color-theme-framework' ) .'</a>',true,'');
}
else if ( $use_excerpt == 'Excerpt' && $excerpt != '' ){
the_excerpt('',FALSE,'');
echo '<a style="margin-left: 5px;display: inline-block;" href="' . get_permalink($post->ID) . '">' . __('Leggi Tutto', 'color-theme-framework') . '</a>';
} ?>
</div><!-- entry-content -->
And this is the piece of functions.php of the excerpt that I have read is the function to limit the character but I don't have understand how change it to return only 5 characters intothe content for the preview of the news for example
/*=======================================
Content Width and Excerpt Redeclared
=======================================*/
if ( !isset( $content_width ) )
$content_width = 980;
// Remove rel attribute from the category list
function remove_category_list_rel($output)
{
$output = str_replace(' rel="category"', '', $output);
return $output;
}
add_filter('wp_list_categories', 'remove_category_list_rel');
add_filter('the_category', 'remove_category_list_rel');
remove_action( 'wp_head', 'feed_links_extra', 3 );
remove_action( 'wp_head', 'feed_links', 2 );
remove_action( 'wp_head', 'rsd_link' );
remove_action( 'wp_head', 'wlwmanifest_link' );
remove_action( 'wp_head', 'index_rel_link' );
remove_action( 'wp_head', 'parent_post_rel_link', 10, 0 );
remove_action( 'wp_head', 'start_post_rel_link', 10, 0 );
remove_action( 'wp_head', 'adjacent_posts_rel_link', 10, 0 );
remove_action( 'wp_head', 'wp_generator' );
add_theme_support( 'automatic-feed-links' );
function new_excerpt_length($length) {
return 30;
}
add_filter('excerpt_length', 'new_excerpt_length');
function new_excerpt_more($more) {
return '...';
}
add_filter('excerpt_more', 'new_excerpt_more');
How can Ilimit the character of the preview of my news to 5 characters?
Your code is using
function new_excerpt_length($length) {
return 30;
}
add_filter('excerpt_length', 'new_excerpt_length');
The above code will limit excerpt to number of words and not characters.
I found this answer from WordPress Stackexchange that has code to limit it with number of characters.
There is simple mathod without changes in function.php
Remove the <?php the_content();?>
insert the below code
<?php echo substr(strip_tags($post->post_content), 0, 46);?>
(Change the 46 to your desire string length)