I am looking to write this "if user is logged in" function but need some help putting the two together for wordpress. Any help would be greatly appreciated! <?php if ( is_user_logged_in() ) { echo 'Welcome, registered user!'; } else { echo 'Welcome, visitor!'; } ?> PHP: <?php /* * Show selected file if value exists * Return value = URL */ if( get_field('upload_file') ): ?><a href="<?php the_field('upload_file'); ?>" ><button class="button color large blue">Download</button></a><?php endif; ?> PHP:
Uhm, what? You only want the download file button to be visible for logged in users, or...? You need to explain a bit better, man
Sorry, yes I am looking to hind the download link from non registered members. Only show the link once one is signed in. The download link is the function link to the download link. Thanks!
Then just place the second code you pasted within the the if-statement in the first bit of code (not the <?php bit, just the rest)
Thanks this is what I ended up using that works. <?php if ( is_user_logged_in() ) { if( get_field('upload_file') ): ?><a href="<?php the_field('upload_file'); ?>" ><button class="button color large blue">Download</button></a><?php endif; } ?> PHP:
Some advice: don't open and close PHP willy-nilly like that, makes the parser work harder for nothing... why are you putting a form element like BUTTON inside an anchor and throwing so many PRESENTATIONAL classes at it? <?php if (is_user_logged_in() && get_field('upload_file')) echo ' <a href="', the_field('upload_file'), '" class="downloadButton">Download</a>'; ?> Code (markup):