WordPress链接到不链接的社交图标

时间:2014-12-16 19:58:13

标签: php wordpress buddypress

我正在尝试使用我在此处找到的一段代码向BuddyPress网站添加社交关注图标: https://buddypress.org/support/topic/display-users-social-follow-buttons-in-profile/

我遵循了downthread的建议并将代码添加到我的插件目录中的bp-custom.php文件中,并且图标显示在他们应该的位置,但社交个人资料的链接显示为文本,当我点击链接它返回404页面。

我确定我有什么不对劲,但我只是无能新发现它。

<?php
//Social Media Icons based on the profile user info
function member_social_extend(){
    $dmember_id = $bp->displayed_user->id;
    $fb_info = xprofile_get_field_data('facebook', $dmember_id);
    $google_info = xprofile_get_field_data('googleplus', $dmember_id);
    $linkedin_info = xprofile_get_field_data('linkedin', $dmember_id);
    $twitter_info = xprofile_get_field_data('twitter', $dmember_id);
    echo '<div class="member-social">';
    if($fb_info||$google_info||$linkedin_info||$twitter_info){
        echo 'My Social: ';
    }

    if ($fb_info) {
    ?>
    <span class="fb-info"><a href="https://www.facebook.com/<?php echo $fb_info; ?>"  title="My Facebook" target="_blank"><img src="<?php bloginfo('wpurl'); ?>/wp-content/themes/family-openstrap-child/images/facebook.png" /></a></span>
<?php
}
    ?>
    <?php
    if ($google_info) {
    ?>
    <span class="google-info"><a href="https://profiles.google.com/<?php echo $google_info; ?>" title="My Googleplus" target="_blank"><img src="<?php bloginfo('wpurl'); ?>/wp-content/themes/family-openstrap-child/images/googleplus.png" /></a></span>
<?php
}
    ?>
    <?php
    if ($linkedin_info) {
    ?>
    <span class="linkedin-info"><a href="https://www.linkedin.com/<?php echo $linkedin_info; ?>" title="My LinkedIn" target="_blank"><img src="<?php bloginfo('wpurl'); ?>/wp-content/themes/family-openstrap-child/images/linkedin.png" /></a></span>
<?php
}
    ?>
    <?php
    if ($twitter_info) {
    ?>
    <span class="twitter-info"><a href="https://twitter.com/<?php echo $twitter_info; ?>" title="My Twitter" target="_blank" class="twitter-follow-button""><img src="<?php bloginfo('wpurl'); ?>/wp-content/themes/family-openstrap-child/images/twitter.png" /></a></span>
<?php
}
echo '</div>';
}
add_filter( 'bp_before_member_header_meta', 'member_social_extend' );
?>

谢谢!

1 个答案:

答案 0 :(得分:0)

看起来xprofile_get_field_data()会创建自己的<a>标记,因此您不必像在那里那样编写一个标记。试试这个:

$fb_info = xprofile_get_field_data(
    '<img src="' . bloginfo('wpurl') . '/wp-content/themes/family-openstrap-child/images/facebook.png" />',
    $dmember_id
);
...
<span class="fb-info"><?php echo $fb_info; ?></span>

不确定xprofile_get_field_data()是否允许您在第一个参数中传递HTML,所以如果这不能正常工作,您可以回归到更简单(没有图像)的地方,如:

$fb_info = xprofile_get_field_data('Facebook', $dmember_id);
相关问题