dongpao1873 2014-12-16 19:58
浏览 49
已采纳

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

I'm attempting to add social follow icons to a BuddyPress site using a section of code that I found here: https://buddypress.org/support/topic/display-users-social-follow-buttons-in-profile/

I followed the suggestion downthread and added the code to a bp-custom.php file in my plugins directory and the icons are showing up where they should but the link to the social profile is showing as text and when I click on the link it returns a 404 page.

I'm sure I have something wrong but I'm just too clueless new to spot it.

<?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' );
?>

Thanks!

  • 写回答

1条回答 默认 最新

  • dongwen1935 2014-12-16 21:32
    关注

    Looks like xprofile_get_field_data() creates its own <a> tag, so you don't have to write one out like you've done there. Try this instead:

    $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>
    

    Not sure if xprofile_get_field_data() will let you pass HTML in the first parameter there, so if that doesn't work quite right, you could fall back to something simpler (no image) like:

    $fb_info = xprofile_get_field_data('Facebook', $dmember_id);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?