I have a custom shortcode tag with a few attributes, and I would like to be able to display its attributes on new lines - to make it more readable to content editors:
[component
attr1 ="value1"
attr2 ="value of the second one"
attr3 ="another"
attr4 ="value"
...
attrN ="valueN"]
The reason behind this requirement is that a few attributes might be quite verbose in content. Unfortunately, wpautop()
adds some nasty extra markup that breaks the $atts
array like this (using php print_r($atts)
):
Array ( [0] => attr1 [1] => ="value1"
/> [3] => attr2 = [4] => "value [5] => of [6] => the [7] => second [8] => one"
/> [10] => "" //...and more like this)
I've tried with the attributes inline:
[component attr1 ="value1" attr2 ="value of the second one" ="value"... attrN ="valueN"]
and the output is as expected:
Array ( [attr1] => value1 [attr2] => value of the second one [attr3] => //...and so on)
is there any way to have the attributes intented and avoid that extra markup that breaks the $args
array?
the function that I use to register the shortcode [component]
extracts the values like this:
function component_func( $atts, $content = null ) {
extract( shortcode_atts( array(
'attr1' => 'attr1',
'attr2' => 'attr2',
'attr3' => 'attr3',
), $atts ) );
// more code
}
I then use those extracted variables to populate another array