The MU forums have moved to WordPress.org

Disappear when empty (7 posts)

  1. kahfooi
    Member
    Posted 13 years ago #

    Below is the code i used in my sidebar to display the user website.

    <div><a href="<?php the_author_meta('user_url'); ?>>View website</a></div>

    My problem is, it still showing "View website" when the user didn't fill in any web url in their profile.

    How can i make it disappear when the user don't have any website in their profile? Thanks!

  2. DeannaS
    Member
    Posted 13 years ago #

    <?php if(strlen(the_author_meta('user_url'))) { ?>
    <div><a href="<?php the_author_meta('user_url'); ?>>View website</a></div>
    <?php
    }
    ?>
  3. kahfooi
    Member
    Posted 13 years ago #

    do i need a echo before the <div>?

  4. kahfooi
    Member
    Posted 13 years ago #

    tried the code, seems like the { } not working. Only output the user_url.

  5. tmoorewp
    Member
    Posted 13 years ago #

    Try:

    <?php
    if(strlen(get_the_author_meta('user_url'))) {
    echo '<div><a href="' . get_the_author_meta('user_url') . '">View website</a></div>';
    }
    ?>
  6. DeannaS
    Member
    Posted 13 years ago #

    Oh yah - what tmoorewp said. I don't use the template tags much and I forget that uh, yah, they're meant for outputting.

  7. kahfooi
    Member
    Posted 13 years ago #

    Much thanks to DeannaS and tmoorewp. It's working now :D

About this Topic