Is there any way to not get the images with get_the_excerpt()? I am using a my_recent_post() function to pull posts onto the home page and I don’t need to have it pull the images within the posts, just some of the text.
Here’s the function that I am using:
function my_recent_post()
{
global $post;
$html = "";
$my_query = new WP_Query( array(
'post_type' => 'post',
'posts_per_page' => 3
));
if( $my_query->have_posts() ) : while( $my_query->have_posts() ) : $my_query->the_post();
$html .= "<div class='item'><a href="" . get_permalink() . ""><span>" . get_the_date() . "</span></a>" . get_the_post_thumbnail() . "
" . get_the_excerpt() . "</div> <div class='clear'></div>";
endwhile; endif;
return $html;
}
add_shortcode( 'news', 'my_recent_post' );
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.