Switch/Case Doesn't recognize shortcode parameters. Why?
-
Hi,
I’m wondering why a switch/case scenario I’ve written will not recognize the parameters in a shortcode function.
Here is a compact version of it:
<?php add_shortcode( 'the_shortcode' , 'the_shortcode_function' ); function the_shortcode_function( $atts, $content=null ) { extract( shortcode_atts( array( 'term' => '', 'url' => 'https://originalurl.com' ), $atts ) ); $output = '<a href="'.$url.'">Link text</a>'; switch( $term ) { case 'foo': $url = 'https://foourl.com'; return $output; break; case 'bar': $url = 'https://barurl.com'; return $output; break; default: return $output; } } ?>
To my untrained eye, I would think that case ‘foo’: would return
<a href="https://foourl.com">Link text</a>
And case ‘bar’: would return
<a href="https://barurl.com">Link text</a>
However, both foo and bar return the default URL string
<a href="https://originalurl.com">Link text</a>
Could somebody explain to me what is happening to prevent my desired output? Much thanks!
Viewing 10 replies - 1 through 10 (of 10 total)
Viewing 10 replies - 1 through 10 (of 10 total)
- The topic ‘Switch/Case Doesn't recognize shortcode parameters. Why?’ is closed to new replies.