shortcode display metainformation as linked image
Question
I am trying to make this shortcode to display a self made meta field called qrbase_code_pass_url
as a linked image.
The image should be static, but should get the dynamic URL from the meta field of the current user.
This is what I've got so far.
function get_qr_image() {
global $current_user; // get current user's information
get_currentuserinfo();
$qr_url = get_currentuserinfo($current_user->qrbase_code_pass_url,24 );
return '<a href="'. $qr_url . '"><img src="https://medlem.nexusesport.no/wp-content/uploads/2018/08/add-to-apple-wallet-logo.png"></a>';
}
add_shortcode('get_user_qr', 'get_qr_image');
This shortcode only break the page.
Thank you for all input!
Solution
@WebElaine is correct. I had to use the wp_get_current_user();
and remove global
.
This is what worked for me
function download_to_wallet() {
$current_user = wp_get_current_user(); // get current user's information
$qr_url = $current_user->qrbase_code_pass_url;
return '<a href="'. $qr_url . '"><img class="qr_download" src="https://example.com/wp-content/uploads/2018/08/add-to-apple-wallet-logo.png" style="width:200px;"></a>';
}
Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange