My shortcode always uses the default value for the single attribute, reviewstoshow, instead of the incoming attribute value. The incoming value has the correct number (per the second half of the dump included below) but the $numberofreviewstoshow var is always set to the default value (6).
Here is the shortcode being used:
[tdp_random_reviews reviewstoshow="8"]
This is the shortcode code:
add_shortcode( 'tdp_random_reviews', 'show_tdp_random_reviews' );
function show_tdp_random_reviews($atts) {
$a = shortcode_atts(
array(
'reviewstoshow' => '6'
),
$atts
);
var_dump($a);
var_dump($atts);
$numberofreviewstoshow = $a['reviewstoshow'];
<snip>
}
Here is the output from the two var_dump() lines:
array(1) { ["reviewstoshow"]=> string(1) "6" }
array(1) { [0]=> string(30) "reviewstoshow="8"" }
Can you tell me where my mistake is? Thanks!
My shortcode always uses the default value for the single attribute, reviewstoshow, instead of the incoming attribute value. The incoming value has the correct number (per the second half of the dump included below) but the $numberofreviewstoshow var is always set to the default value (6).
Here is the shortcode being used:
[tdp_random_reviews reviewstoshow="8"]
This is the shortcode code:
add_shortcode( 'tdp_random_reviews', 'show_tdp_random_reviews' );
function show_tdp_random_reviews($atts) {
$a = shortcode_atts(
array(
'reviewstoshow' => '6'
),
$atts
);
var_dump($a);
var_dump($atts);
$numberofreviewstoshow = $a['reviewstoshow'];
<snip>
}
Here is the output from the two var_dump() lines:
array(1) { ["reviewstoshow"]=> string(1) "6" }
array(1) { [0]=> string(30) "reviewstoshow="8"" }
Can you tell me where my mistake is? Thanks!
Share Improve this question asked Apr 30, 2020 at 18:46 BCarnathanBCarnathan 211 bronze badge 5 |1 Answer
Reset to default 2The quotes in the shortcode call were not standard (despite them looking so). Replacing the old double quote characters with typed-into-notepad, copied, and pasted new quotes in the theme editor resolved the problems.
Thanks to @WebElaine and @vancoder for the help!
var_dump
() of$numberofreviewstoshow
? It looks right -$a['attributename']
. You might also want to double-check types (string vs. integer) and quotes (smart vs. plain) if that's not giving you the value you expect. – WebElaine Commented Apr 30, 2020 at 18:56var_dump
should be outputting an array, not a string. Are you sure your shortcode itself is correct? You're not using weird quotes around the 8, or something? Because WP is not recognizing the parameter. – vancoder Commented Apr 30, 2020 at 22:08