0

I want to add a URL on my website. Something like website.com/drive_folder

When someone presses that link (and he can only see it on a page when he is logged in), it will send him to a Google Drive folder that has been manually set in advance using a custom field in his user profile.

How do I go about doing that?

0

Use is_user_logged_in() to show link only or logged in users.

And use the_author_meta() to get url to google drive.

Like this inside The Loop:

<?php if(is_user_logged_in()): ?>
  <a href="<?php the_author_meta('google_drive_url') ?>">Click to open Google Drive</a>
<?php endif; ?>
0

If you already set a custom field with the url of the logged in user, then you can use something similar to what Alexey responded, only I think the_author_meta returns the content of the meta field for the author of the current post, and not the current logged in user. This code will do what you want:

<?php 
    if (is_user_logged_in()){
       $current_user = wp_get_current_user();
       $curr_usr_id = $current_user->ID;
       $google_drive_url = get_user_meta($curr_usr_id, 'google_drive_url', true);
       if($google_drive_url != ''){ 
?>
          <a href="<?php echo $google_drive_url; ?>">Go To The exclusive Gogle Drive Folder</a>
<?php   
       }
    }
?>
3
  • Getting that information is easy. My problem is making sure that mysite.com/user_drive gets redirected when it is pressed on the website to the get_user_meta() value... – Tsahi Levent-Levi Sep 7 '15 at 5:18
  • I don't understand the question. If you want that when the user clicks in the link, the link will land in the url in the meta valua url, this code will do, but I don't know to where you want the redirection. – Eduardo Sánchez Hidalgo Urías Sep 7 '15 at 21:24
  • Assume the link is static on the page, but needs to redirect to a URL based on the user who clicks it. – Tsahi Levent-Levi Sep 9 '15 at 6:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.