0

Here's a shortcode of mine:

 function sc_link( $atts ) { extract( shortcode_atts( array( 'page' => '', 'style' => 'button', 'window' => 'self', 'label' => 'Missing Label Tag: label=""', ), $atts ) ); return '<a href="' . $page . '" class="' . $style. '" target="_' . $window . '">' . $label . '</a>'; } add_shortcode( 'mylink', 'sc_link' ); 

What I want to be able to do is a conditional before the return: if $window = 'new' then echo 'blank'.

2 Answers 2

1

Think this is what your trying to do what id suggest doing is leaving window blank and just doing an if statement on that

How you want it

 function sc_link( $atts ) { extract( shortcode_atts( array( 'page' => '', 'style' => 'button', 'window' => 'self', 'label' => 'Missing Label Tag: label=""', ), $atts ) ); if($window == "new"){ $link = '<a href="' . $page . '" class="' . $style. '" target="_blank">' . $label . '</a>'; }else{ $link = '<a href="' . $page . '" class="' . $style. '" target="_self">' . $label . '</a>'; } return $link; } add_shortcode( 'mylink', 'sc_link' ); 

How it should be

 function sc_link( $atts ) { extract( shortcode_atts( array( 'page' => '', 'style' => 'button', 'window' => '', 'label' => 'Missing Label Tag: label=""', ), $atts ) ); if(!$window){ $link = '<a href="' . $page . '" class="' . $style. '" target="_self">' . $label . '</a>'; }else{ $link = '<a href="' . $page . '" class="' . $style. '" target="' . $window . '">' . $label . '</a>'; } return $link; } add_shortcode( 'mylink', 'sc_link' ); The your shortcode will be link [shorcode page="" window="" label=""] 
Sign up to request clarification or add additional context in comments.

Comments

0

Here is an easy short code conditional output example. I would recommend being sparing with this type of syntax because it can get lost in the fray.

echo ($window === 'new') ? $window : ''; 

This format is conditional ? what to do if true : what to do if false

2 Comments

Thanks for this. Trying to understand the syntax. How would I tell it to echo "blank" if value is "new"?
swap them. echo ($window === 'new') ? 'blank' : $window

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.