How do I Add HTML to the_excerpt() & the_content() Output?

get_the_excerpt() returns the excerpt, but only after applying get_the_excerpt filters to it. This causes infinite recursion, as your filter handler will be called to an infinite depth. Of course, the best solution is the css one (see @spacegrrl’s answer), but if you have your reasons for keeping that <span>, please note that the excerpt can … Read more

Return only post(s) which have post_excerpt

Something along these lines should work, not tested for syntax errors though function random_post() { $args = array( ‘post_type’ => ‘post’, ‘orderby’ => ‘rand’, ‘posts_per_page’ => 1, ); $post = query_posts( $args ); } if(!$post->post_excerpt){ random_post(); } // Then down here you would do whatever with the $post object

Using get_the_excerpt() Before The Loop

So you are basically also looking for a fallback in case your excerpt is empty? I suppose this question/answer could be helpful for you: “get_the_excerpt() with fallback like the_excerpt()“. It describes, how to build your own “excerpt” in case there is none – like this: $excerpt = get_the_content(); $excerpt = esc_attr( strip_tags( stripslashes( $excerpt ) ) … Read more

the_excerpt filter with an empty excerpt

If you are talking about excerpt set manually in the excerpt field of post then you can use following code in the functions.php file of your child theme or plugin to display default excerpt if no excerpt it set. function display_default_excerpt( $excerpt ) { if ( has_excerpt() ) { return $excerpt; } else { return … Read more

Show the excerpt in a loop

get_the_excerpt function has issues using it with wp_get_recent_posts so instead of get_the_excerpt function use wp_trim_excerpt function in your code as displayed below. <?php $args = array( ‘numberposts’ => ‘3’ ); $recent_posts = wp_get_recent_posts( $args ); foreach( $recent_posts as $recent ){ ?> <div class=”wpb_column vc_column_container vc_col-sm-4″> <div class=”wpb_wrapper”> <div class=”wpb_text_column wpb_content_element wpb_animate_when_almost_visible wpb_left-to-right wpb_start_animation”> <div class=”wpb_wrapper”> … Read more

Line in excerpt and max 5 lines

If you type your poets like this in the editor and separate them by new lines: This is a phrase This is another phrase Then you can divide them by new line, and then return them to the front-end. You can do this by using the get_the_excerpt filter. This goes in your theme’s functions.php file: … Read more

Display custom fields on post excerpt or teaser

The way to retreive some meta data is knowing the name of the custom field, for my example I will use: listing, property and address; normally this can be done after while (have_posts()) : the_post(); $listing = get_post_meta($post->ID, ‘listing’, true); $property = get_post_meta($post->ID, ‘property’, true); $address = get_post_meta($post->ID, ‘address’, true); then you can print the … Read more

the_excerpt producing empty output

Does the_excerpt() work if you remove the custom functions you have? Firstly, for sanities sake to make sure the excerpt has a value, could you try replacing your current excerpt call with this? <?php echo get_post_field(‘post_excerpt’, $post->ID); ?> If it does work then the problem is most likely related to your custom functions.

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