WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Custom fields check for input (5 posts)

  1. james-dg
    Member
    Posted 2 years ago #

    Sounds like a pretty weird thing to ask but here is what I'm looking for...

    I have some custom fields on the user area in wordpress. These are then shown on the author page.
    What I have right now is users enter their facebook link and it will add a facebook icon to the page. The only problem is if a user doesn't enter their url there is just a facebook icon there with no link.
    Is there a way to only show the image if a url has been added?
    Thanks :)

  2. esmi
    Theme Diva & Forum Moderator
    Posted 2 years ago #

    How are you calling the link & icon?

  3. james-dg
    Member
    Posted 2 years ago #

    <a href="
    <?php $user = $curauth;
    
    // is there someone logged?
    if ($user->ID) {
    $value = cimy_uef_sanitize_content(get_cimyFieldValue($user->ID, 'FACEBOOKURL'));
    echo $value;
    }?>">
    <img src="<?php bloginfo('template_directory'); ?>/images/fbicon.png" alt="find us on facebook"/></a>

    Not sure If i'm even doing it right :')

  4. esmi
    Theme Diva & Forum Moderator
    Posted 2 years ago #

    Try:

    <?php if( $value && $value !='' ):?> <img src="<?php bloginfo('template_directory'); ?>/images/fbicon.png" alt="find us on facebook"/></a><?php endif;?>

  5. james-dg
    Member
    Posted 2 years ago #

    Thank you Esmi :)
    I had to alter it slightly because it wouldn't show the closing tag on the link.

    <a target="_blank" href="http://www.facebook.com/<?php $user = $curauth;
    if ($user->ID) {
    $value = cimy_uef_sanitize_content(get_cimyFieldValue($user->ID, 'FACEBOOKURL'));
    }?>
    <?php echo $value ?>">
    <?php if( $value && $value !='' ):?><img src="<?php bloginfo('template_directory'); ?>/images/fbicon.png" alt="Find us on facebook"/><?php endif;?>

    See it in action :)

Topic Closed

This topic has been closed to new replies.

About this Topic