I have a strange problem…
I have a PHP snippet that i’m using inside WordPress and the plugin SNIPPETS.
The code is working is fine in Chrome but for whatever reason, nothing is showing up in Edge or Firefox.
I just want to display a different icon based on a custom user field.
Here is my code
function ajax_13xx()
{ $current_user = wp_get_current_user();
if ( $current_user->s_managed == Yes ) {
return '<div align="right"><img src="abc.com/onswitch20.jpg"> </div>' ;
}
if ( $current_user->s_managed == No ) {
return '<div align="right"><img src="abc.com/offswitch20.jpg"></div>' ;
}
}
add_shortcode('managetoggle', 'ajax_13xx');
I’m using Elementor and the Shortcode widget for [managetoggle]
Any feedback would be appreciated!
Regards,
Nathalie
2
Answers
Found solution already...
Added this line...
Use an
else
block.Because this is a boolean value, we can simply use
else
, you want theNo
in else because we could use0
orNo
orNull
Generally anything that isfalsy
. This will also be like a plank time (smallest unit of time possible) faster as only one condition needs to be checked.Another even better way to write this is like this:
Then you keep your code a bit more DRY (don’t repeat yourself)