I am not sure that a filter on the_content
is the way to go here. If I understand you, I think that all you need is something like the following your theme– cribbed from the two Codex pages listed below and altered slightly.
if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
the_post_thumbnail();
echo '<a class="moretag" href="'. get_permalink($post) . '"> Read the full article...</a>';
} else {
the_content();
}
That may not look right since I don’t know what your theme code looks like but that it the idea.
If you are going to filter the_content
I think what you want is more like this:
function insertfeaturedimage($content) {
global $post;
if ( current_theme_supports( 'post-thumbnails' ) ) {
if (is_page() || is_single() || is_front_page()) {
$thumb = get_the_post_thumbnail('page-single');
if (!empty($thumb)) {
$content = $thumb.'<a class="moretag" href="'. get_permalink($post) . '"> Read the full article...</a>';
}
}
}
return $content;
}
add_filter( 'the_content', 'InsertFeaturedImage' );
Note: I used get_permalink($post);
instead of get_permalink($post->ID);
on purpose. Despite the docs, get_permalink
will accept the $post
object itself and if given the object won’t run get_post
. You can save a query (under some circumstances anyway).
http://codex.wordpress.org/Function_Reference/the_post_thumbnail