Custom excerpt length filter doesn’t work

For anyone wondering, as custom excerpts don’t get trimmed by the excerpt_length filter hook, try adding this filter: function trim_custom_excerpt($excerpt) { if (has_excerpt()) { $excerpt = wp_trim_words(get_the_excerpt(), apply_filters(“excerpt_length”, 55)); } return $excerpt; } add_filter(“the_excerpt”, “trim_custom_excerpt”, 999);

How to disable automatic excerpt generation *in admin*?

Just illustrating this in full effect here with the filters and functions for both the adding of custom column and testing for excerpt existence. Note, I’ve purposely ripped the guts out of has_excerpt to show you in effect what is occurring under the hood. You can use !has_excerpt in its place. add_filter(‘the_excerpt’, ‘no_excerpt’); add_filter(‘manage_posts_columns’ , … Read more

How to echo excerpts with wp_list_pages?

If you want to make use of all the nifty filters for the title and excerpt/content (and why would you not want that?) you should loop through a custom query instead of using get_pages and the pages’ plain contents: <?php $args = array( ‘post_type’ => ‘page’, ‘post_status’ => ‘publish’, ‘posts_per_page’ => -1, ‘post_parent’ => $post->ID, … Read more

Get post excerpt and title by specific post ID?

Your get_excerpt() function uses the global $post variable, which is out of scope inside your function. // Changing excerpt length function get_excerpt($count){ $permalink = get_permalink($post->ID); $excerpt = get_the_content(); $excerpt = strip_tags($excerpt); $excerpt = substr($excerpt, 0, $count); $excerpt = substr($excerpt, 0, strripos($excerpt, ” “)); $excerpt = $excerpt.’… <a href=”‘.$permalink.'”>Read More</a>’; return $excerpt; } That means that … Read more

How to change / delete product short description in Woocommerce

Th function wp_set_object_terms() will not work to set post object properties. To add/update/delete product short description there is mainly 2 ways: 1) the WordPress way from a post ID using wp_update_post() function this way: $product_id = $post->ID; // or get_the_id() or $product->get_id() (when $product is available); // The product short description (for testing) $new_short_description = … Read more

Getting first 20 words without excerpt

Use wp_trim_words() wp_trim_words( get_the_content(), 20 ) As you’re outside the main loop wp_trim_words( $recent[ ‘post_content’ ], 20 ) If you want to apply the same filters as to the_content() in the main loop wp_trim_words( apply_filters( ‘the_content’, $recent[ ‘post_content’ ] ), 20 )

How to get the excerpt of a page before more tag?

The content is manipulated by the get_the_content function, and that function always assumes the current post in the Loop. You can’t pass it an ID, strangely. The easiest way to get just the bit before the more for an arbitrary post ID is: $p = get_post(1); $p = preg_split( ‘/<!–more(.*?)?–>/’, $p->post_content ); echo $p[0]; There … Read more

Writing a custom excerpt function

The easiest way is to use strip_tags(). // Remove all html from the excerpt. function custom_excerpt( $text ) { return strip_tags( $text ); } add_filter( ‘the_excerpt’, ‘custom_excerpt’ ); If you want to get fancy and trim the excerpt length, you can use this function. // Trim default excerpt length from 55 chars to 20. function … Read more

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