[英]Add WP permalink to PHP function
下面的代码将图像添加到我的wordpress RSS feed中。 我要制作它,以便图像自动超链接回相应的帖子。 代码在我主题的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函数并将其传递给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;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.