Conditional display via shortcode

I want to set a show/hide condition via a shortcode on a paragraph

Here is the shortcode (normal return is “true”):

add_shortcode( 'button-display' , 'button_display' );
function button_display(){
	$display = true;
	if( $display == true ) {
		$ret = true;
	} else {
	    $ret = false;
	}
	return "$ret";
}

Here is the conditional display set in paragraph:

But nothing is displayed.
I don’t understand what is wrong.
Could you help me, please.

Environment info

  • WordPress version: 6.0.1
  • Gutenberg Plugin version: not installed
  • Cwicly Plugin version: 1.1.8.5.7
  • Cwicly Theme version: 1.0.3

Hi @weedor,

Indeed, thanks for bringing this up.
The current condition is looking for a 'true' ('false' for false) return instead of true.

Not quite sure what my initial desire was behind this but it certainly doesn’t fulfil the requirements so we’ll be modifying this in the next update.

Basically, it currently works if like this:

add_shortcode( 'button-display' , 'button_display' );
function button_display(){
	$display = true;
	if( $display == true ) {
		$ret = 'true';
	} else {
	    $ret ='false';
	}
	return "$ret";
}

Sorry for the inconvenience but this will be fixed in the next update.

1 Like

Thank you very much @Louis

Hello @weedor,

This should be fixed in 1.1.9.1, thanks for bringing it up!

1 Like