Custom shortcode's
-
I’ve been using some custom shortcodes in my template. Thing is… I have to many and they are almost all identical. (over 40 times the same 4 lines of code with only 1 numerical change in the code)
function t1_func( $atts ){ return '<img class="alignnone" src="/Tekens%201.png" alt="" width="35" height="41" />'; } add_shortcode( 't1', 't1_func' );
Above is one current shortcode example. I use this same piece of code 9 times. Going from t1 to t9.
I am now trying to make this code shorter and make it work for other attributes (b,t and k).
I experimented with the following code:
function m_func( $atts ) { extract( shortcode_atts( array('b','t','k','wi','dr',) , $atts ) ); if ($atts = b) { return '<img class="alignnone" src="/Bamboe%20' . ($b) . '.png" alt="" width="35" height="41" />'; } if ($atts = t) { return '<img class="alignnone" src="/Tekens%20' . ($t) . '.png" alt="" width="35" height="41" />'; } if ($atts = k) { return '<img class="alignnone" src="/Kringen%20' . ($k) . '.png" alt="" width="35" height="41" />'; } } add_shortcode( 'm', 'm_func' );
But this does not work, can anyone help me on this subject?
P.S.
I read that attribute parameters require a default… but in my case there are no defaults… the attribute should only be used when it is entered…
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Custom shortcode's’ is closed to new replies.