Limit the_excerpt with max of x characters

add_filter(‘wp_trim_excerpt’, function($text){ $max_length = 140; if(mb_strlen($text, ‘UTF-8’) > $max_length){ $split_pos = mb_strpos(wordwrap($text, $max_length), “\n”, 0, ‘UTF-8’); $text = mb_substr($text, 0, $split_pos, ‘UTF-8′); } return $text; }); This should take into account your max length and split the text at the nearest word boundary. Apply the filter, and call the_excerpt(); in your templates Apparently there’s a … Read more

“Read more” link doesn’t show up when the post length is under the excerpt length

The reason is the following check in the wp_trim_words() function: if ( count( $words_array ) > $num_words ) { array_pop( $words_array ); $text = implode( $sep, $words_array ); $text = $text . $more; } else { $text = implode( $sep, $words_array ); } You can therefore try the following: add_filter( ‘wp_trim_words’, function( $text, $num_words, $more … Read more

Remove images from get_the_excerpt

If you read the Codex entry for get_the_excerpt(), you will find this: If the post does not have an excerpt, this function applies wp_trim_excerpt to the post content and returns that generated string with “[…]” at the end. wp_trim_excerpt is applied via the get_the_excerpt filter and can be removed. The wp_trim_excerpt() function: Generates an excerpt … Read more

How to set default metaboxes on user creation?

Based on this Answer by t31os. Here, all meta boxes are being set to invisible, so simply remove from the array the ones that are meant to be visible. add_action(‘user_register’, ‘wpse_58645_set_user_metaboxes’); function wpse_58645_set_user_metaboxes( $user_id ) { update_user_meta( $user_id, ‘metaboxhidden_post’, array( ‘authordiv’, ‘categorydiv’, ‘commentstatusdiv’, ‘formatdiv’, ‘postcustom’, ‘postexcerpt’, ‘postimagediv’, ‘slugdiv’, ‘tagsdiv-post_tag’, ‘trackbacksdiv’, ) ); } For registered … Read more

Disable WYSIWYG rich text editor only on post excerpt

Excerpts can be automatically generated in which case you have some control over them or manually generated in which case there is very little control available, and the wordpress way is that they may have any type of content. if you need something more restrictive you will need to create your own “meta box” for … Read more

End excerpt at the end of the sentence

Use this function instead. Then put the_excerpt(); in your template. /** * Find the last period in the excerpt and remove everything after it. * If no period is found, just return the entire excerpt. * * @param string $excerpt The post excerpt. */ function end_with_sentence( $excerpt ) { if ( ( $pos = mb_strrpos( … Read more

Limit the Excerpt field in WP-Admin in words

You can use something like jQuery Simply Countable plugin and attach it to excerpt input. Limit_Excerpt_Words::on_load(); class Limit_Excerpt_Words { static function on_load() { add_action( ‘admin_enqueue_scripts’, array( __CLASS__, ‘admin_enqueue_scripts’ ) ); } static function admin_enqueue_scripts() { global $hook_suffix; if ( ‘post.php’ == $hook_suffix || ‘post-new.php’ == $hook_suffix ) { wp_enqueue_script( ‘jquery-simply-countable’, plugins_url( ‘/jquery.simplyCountable.js’, __FILE__ ), array( … Read more

Custom Excerpt is returning 52 characters and not 52 words

The function you want is wp_trim_words(), example: function themeTemplate_trim_excerpt( $content ) { $more=”…”; //where $more is optional return wp_trim_words($content, 52, $more); } remove_filter(‘get_the_excerpt’, ‘wp_trim_excerpt’); add_filter(‘get_the_excerpt’, ‘template_trim_excerpt’);

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)