每个页面上的社交分享插件
Social Sharing plugin on every page
我最近一直在开发一个社交分享插件,它固定在页面的右侧(已修复 CSS)。
我一直在使用挂钩 'the_content' 来显示侧边栏,但我相信大家都知道,这会在 post 上显示侧边栏,但不会显示类别 pages/blog 提要.
我曾尝试使用 'the_excerpt' 在博客 feed/category 页面上显示边栏,但我觉得有一种更简单的方法可以达到相同的结果。
这是我对插件的目标的一个很好的例子:https://wordpress.org/plugins/custom-share-buttons-with-floating-sidebar/
这里是插件的前端显示部分(我想是问题所在):
function add_social_share_icons($content) {
$html = "<ul id='social-sidebar'>";
global $post;
$url = get_permalink($post->ID);
$url = esc_url($url);
if(get_option("social-share-facebook") == 1)
{
$html = $html . "<li><a class='fa fa-facebook' target='_blank' href='http://www.facebook.com/sharer.php?u=" . $url . "'><span>Facebook</span></a></li>";
}
if(get_option("social-share-twitter") == 1)
{
$html = $html . "<li><a class='fa fa-twitter' target='_blank' href='https://twitter.com/share?url=" . $url . "'><span>Twitter</a></li>";
}
if(get_option("social-share-linkedin") == 1)
{
$html = $html . "<li><a class='fa fa-linkedin linkedin' target='_blank' href='http://www.linkedin.com/shareArticle?url=" . $url . "'><span>LinkedIn</span></a></li>";
}
if(get_option("social-share-google") == 1)
{
$html = $html . "<li><a class='fa fa-google gplus' target='_blank' href='https://plus.google.com/share?url=" . $url . "'><span>Google+</span></a></li>";
}
if(get_option("social-share-mail") == 1)
{
$html = $html . "<li><a class='fa fa-envelope github' href='mailto:?body=" . $url . "'><span>Email</span></a></li>";
}
$html = $html . "</ul>";
return $content = $html . $content;
}
add_filter("the_content", "add_social_share_icons");
如有任何帮助,我们将不胜感激。
编辑: 我试过:add_action("wp_footer", "add_social_share_icons");
但没有运气,我还检查了页脚文件,认为 wp_footer()
可能不存在,但肯定包括在内。
如果目标是将 link 分享给 "current page",您可以随时将其挂接到 wp_footer()
我最近一直在开发一个社交分享插件,它固定在页面的右侧(已修复 CSS)。
我一直在使用挂钩 'the_content' 来显示侧边栏,但我相信大家都知道,这会在 post 上显示侧边栏,但不会显示类别 pages/blog 提要.
我曾尝试使用 'the_excerpt' 在博客 feed/category 页面上显示边栏,但我觉得有一种更简单的方法可以达到相同的结果。
这是我对插件的目标的一个很好的例子:https://wordpress.org/plugins/custom-share-buttons-with-floating-sidebar/
这里是插件的前端显示部分(我想是问题所在):
function add_social_share_icons($content) {
$html = "<ul id='social-sidebar'>";
global $post;
$url = get_permalink($post->ID);
$url = esc_url($url);
if(get_option("social-share-facebook") == 1)
{
$html = $html . "<li><a class='fa fa-facebook' target='_blank' href='http://www.facebook.com/sharer.php?u=" . $url . "'><span>Facebook</span></a></li>";
}
if(get_option("social-share-twitter") == 1)
{
$html = $html . "<li><a class='fa fa-twitter' target='_blank' href='https://twitter.com/share?url=" . $url . "'><span>Twitter</a></li>";
}
if(get_option("social-share-linkedin") == 1)
{
$html = $html . "<li><a class='fa fa-linkedin linkedin' target='_blank' href='http://www.linkedin.com/shareArticle?url=" . $url . "'><span>LinkedIn</span></a></li>";
}
if(get_option("social-share-google") == 1)
{
$html = $html . "<li><a class='fa fa-google gplus' target='_blank' href='https://plus.google.com/share?url=" . $url . "'><span>Google+</span></a></li>";
}
if(get_option("social-share-mail") == 1)
{
$html = $html . "<li><a class='fa fa-envelope github' href='mailto:?body=" . $url . "'><span>Email</span></a></li>";
}
$html = $html . "</ul>";
return $content = $html . $content;
}
add_filter("the_content", "add_social_share_icons");
如有任何帮助,我们将不胜感激。
编辑: 我试过:add_action("wp_footer", "add_social_share_icons");
但没有运气,我还检查了页脚文件,认为 wp_footer()
可能不存在,但肯定包括在内。
如果目标是将 link 分享给 "current page",您可以随时将其挂接到 wp_footer()