First, I wouldn’t modify the string/word length of the content. Semantically, you’re dealing with an excerpt, so let’s focus on that.
Second, to limit the number of words returned for the excerpt, simply filter excerpt_length
:
<?php
function wpse52673_filter_excerpt_length( $length ) {
// Return (integer) value for
// word-length of excerpt
return 150;
}
add_filter( 'excerpt_length', 'wpse52673_filter_excerpt_length' );
?>
The added benefit of using the_excerpt()
is that, for auto-generated excerpts, no HTML is parsed. So, if you don’t use user-defined excerpts, you’re done.
However, if you do use user-generated excerpts, but still want to strip HTML tags, simply remove any or all of the following filters that are applied to the_excerpt
:
add_filter( 'the_excerpt', 'wptexturize' );
add_filter( 'the_excerpt', 'convert_smilies' );
add_filter( 'the_excerpt', 'convert_chars' );
add_filter( 'the_excerpt', 'wpautop' );
add_filter( 'the_excerpt', 'shortcode_unautop');
To remove one, simply call, e.g.:
remove_filter( 'the_excerpt', 'wptexturize' );