WordPress 给 Feed 加上自定义 Logo 图标

2017-03-15 06:40 484 6 条评论 龙笑天下
Dragon主题购买

Wordpress 给 Feed 加上自定义 Logo 图标

今天就给大家介绍一个不常见的小功能,就是给你博客 RSS 的 Feed 订阅加上一个自定义的小 logo 图标。效果可参考下图,具体的打开击本站的 Feed 地址看看:https://www.ilxtx.com/feed/(PS:貌似只在 Firefox 中看到...)。

Wordpress 给 Feed 加上自定义 Logo 图标

将下面的代码放到 functions.php 中即可:

/**
 * WordPress 给 Feed 加上自定义 Logo 图标 - 龙笑天下
 * https://www.ilxtx.com/feed-your-image-via-atom-or-rss.html
 */
// add icon and logo to Atom feeds
add_action('atom_head','lxtx_atom_feed_add_icon');
add_action('comments_atom_head','lxtx_atom_feed_add_icon');
function lxtx_atom_feed_add_icon() { ?>

	<feed>
		<icon><?php bloginfo_rss('url'); ?>/favicon.ico</icon>
		<logo><?php bloginfo_rss('url'); ?>/favicon.ico</logo>
	</feed>

<?php }

// add icon and logo to RSS feeds
add_action('rss_head','lxtx_rss_feed_add_icon');
add_action('rss2_head','lxtx_rss_feed_add_icon');
add_action('commentsrss2_head','lxtx_rss_feed_add_icon');
add_action('atom_head','lxtx_rss_feed_add_icon');
add_action('comments_atom_head','lxtx_rss_feed_add_icon');
function lxtx_rss_feed_add_icon() { ?>

	<image>
		<url><?php bloginfo_rss('url'); ?>/favicon.ico</url>
		<title><?php bloginfo_rss('name'); ?></title>
		<link><?php bloginfo_rss('url'); ?></link>
		<width>32</width>
		<height>32</height>
		<description><?php bloginfo('description'); ?></description>
	</image>

<?php }

// add icon and logo to RDF feeds
add_action('rdf_header','lxtx_rdf_feed_add_icon');
function lxtx_rdf_feed_add_icon() { ?>

	<image rdf:about="<?php bloginfo_rss('url'); ?>/favicon.ico">
		<title><?php bloginfo_rss('name'); ?></title>
		<url><?php echo get_template_directory_uri(); ?>/images/logo.gif</url>
		<link><?php bloginfo_rss('url'); ?></link>
		<description><?php bloginfo('description'); ?></description>
	</image>

<?php }

代码取自《Customizing WordPress Feeds | Digging Into WordPress

其中的 2 个32是指 logo 图标的长和宽,可自行调整。

「点点赞赏,手留余香」

还没有人赞赏,快来当第一个赞赏的人吧!

声明:本文为原创文章,版权归所有,欢迎分享本文,转载请保留出处!

2017-02-05

2017-03-31

发表评论

表情 格式 贴图 链接 私密 签到
Dragon主题购买阿里云特价云服务器1核2G低至86元,N4共享型服务器3年仅需799元腾讯云特价云服务器1核2G 88元/年 2核4G3M688元/3年,更有千元代金券礼包免费领!
评论
正在努力加载中...
扫一扫二维码分享
×
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept”, you consent to the use of ALL the cookies. Learn more