添加WP永久链接到PHP函数


Add WP permalink to PHP function

下面的代码将图像添加到我的wordpress RSS提要中。我想让它,使图像自动超链接回相应的帖子。代码在我的主题的functions.php

    function wcs_post_thumbnails_in_feeds( $content ) {
    global $post;
    if( has_post_thumbnail( $post->ID ) ) {
        $content = get_the_post_thumbnail( $post->ID ) . '<span class="text">' . $content . '</span>';
    }
    return $content;
}
add_filter( 'the_excerpt_rss', 'wcs_post_thumbnails_in_feeds' );
add_filter( 'the_content_feed', 'wcs_post_thumbnails_in_feeds' );
Can I change this so that the post_thumbnail is automatically wrapped with a link to the post?

我如何包装get_the_post_thumbnail($post->ID)部分代码与链接?由于

您可以使用get_permalink函数并将post ID传递给它。

function wcs_post_thumbnails_in_feeds( $content ) {
        global $post;
        if( has_post_thumbnail( $post->ID ) ) {
            $content = '<a href="' . get_permalink( $post->ID ) . '">' . get_the_post_thumbnail( $post->ID ) . '</a><span class="text">' . $content . '</span>';
        }
        return $content;
    }