Custom wp_trim_words() function not trimming right

What about using this function in functions.php: function new_excerpt_length($length) { return 20; } add_filter(‘excerpt_length’, ‘new_excerpt_length’); And then getting it by adding<?php the_excerpt()?> to php template? OR: <?php $string = get_the_excerpt(); if (strlen($string) <=20) {echo ” . $string . ”;} else {echo ” . substr($string, 0, 20) . ‘…’;}?> In this case 20 is characters

Automatic Excerpt Not Working

It turns out my client added shortcodes to the beginning of the posts and the only thing I can think of is that the_excerpt was choosing what words to use from the content before stripping shortcode tags out, thus, returning a blank excerpt. Hope this helps someone in the future

Custom excerpt showing first paragraph (with HTML formatting)

Here is a function that keeps HTML tags in tact, adds a “Read More” link at the end of the excerpt and trims the excerpt after the first paragraph. if ( ! function_exists( ‘wpse0001_custom_wp_trim_excerpt’ ) ) : function wpse0001_custom_wp_trim_excerpt($wpse0001_excerpt) { global $post; $raw_excerpt = $wpse0001_excerpt; if ( ” == $wpse0001_excerpt ) { $wpse0001_excerpt = get_the_content(”); … Read more

How to hide and content from auto-generated excerpts?

To filter the content only when an auto-excerpt is generated you have to chain the hooks: Hook into get_the_excerpt and register a filter for the_content. In the second filter remove both elements and their content before the excerpt can see it. Sample: add_filter( ‘get_the_excerpt’, ‘t5_excerpt_clean_up’, 1 ); /** * Register handler for auto-generated excerpt. * … Read more

How to programmatically bring back “excerpts” field in post editor in WP 3.1+

http://wordpress.org/support/topic/troubleshooting-wordpress-31-master-list?replies=14 a few posts down has instructions for default ‘ON’ options // Change what’s hidden by default add_filter(‘default_hidden_meta_boxes’, ‘be_hidden_meta_boxes’, 10, 2); function be_hidden_meta_boxes($hidden, $screen) { if ( ‘post’ == $screen->base || ‘page’ == $screen->base ) { // removed ‘postcustom’, $hidden = array( ‘slugdiv’, ‘trackbacksdiv’, ‘postexcerpt’, ‘commentstatusdiv’, ‘commentsdiv’, ‘authordiv’, ‘revisionsdiv’ ); } return $hidden; }

How to Remove Checkbox for Excerpt Under Screen Options

You can do this with CSS. .metabox-prefs label[for=”postexcerpt-hide”] { display: none; } In regard to adding the CSS to the admin section, you have two options: Option 1: Add the CSS to a stylesheet and enqueue it using the admin_enqueue_scripts hook. function load_custom_wp_admin_style() { wp_register_style( ‘custom_wp_admin_css’, get_template_directory_uri() . ‘/admin-style.css’, false, ‘1.0.0’ ); wp_enqueue_style( ‘custom_wp_admin_css’ ); … Read more

Thumbnail + Excerpt = loss in word count

For everybody that is looking for a great excerpt that keep html tags in tact and want the excerpt not to cut off mid sentence and have a true word count, here is the code function pietergoosen_custom_wp_trim_excerpt($text) { global $post; $raw_excerpt = $text; if ( ” == $text ) { $text = get_the_content(”); $text = … Read more

How to customize read more link

There are a number of ways this can be achieved, some more complex than others, some offering more functionality than others, however it all depends on your usage-case. For now, the most simple method is to use a combination of, custom fields and a… conditional if/else statement Step 1) In your post edit screen you … Read more

get excerpt without images

Use the_excerpt(); wordpress function to show only text. That function will filter out some html tags such as <img> , <a>. A useful alternative to show only plain text. Note – The the_excerpt() function internally uses get_the_excerpt() to get excerpt and return a new string by filtering tags such as <img>, <a> tags. It also … Read more

How to get the excerpts of all children pages

Firstly, it should be post_excerpt. Secondly, this just stores the manually added excerpt, so it returns empty if you don’t have one. Thirdly, you could setup_postdata: <?php $pagechildren = get_pages( array( ‘child_of’ => $post->ID ) ); ?> <?php foreach ( $pagechildren as $post ) : setup_postdata( $post ); ?> // code <?php endforeach; wp_reset_postdata(); ?> … Read more