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( 
                'reviewstoshow' => '6'


    $numberofreviewstoshow = $a['reviewstoshow'];



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!

  • Have you tried a 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 Apr 30 at 18:56
  • Just tried that again to confirm my memory: var_dump($numberofreviewstoshow); Returns: string(1) "6" I replaced all of the quotes to ensure they are dumb. "It looks right" — thanks for making me feel less dumb! Have any more ideas? – BCarnathan Apr 30 at 20:33
  • That second var_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 Apr 30 at 22:08
  • You solved the problem, vancoder. I replaced all quotes in the code per WebElaine but did not change out the quotes in the call. I don't know how wonky quotes got in there in the first place but thanks for the help both of you!!! – BCarnathan Apr 30 at 22:38

The 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!

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.