WordPress链接到社交图标未链接


WordPress links to social icons not linking

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

我按照建议向下线程并将代码添加到我的插件目录中的 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' );
?>

谢谢!

看起来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);