0

I am trying to add a shortcode to my theme file and when I do it, I get this on the front end:

Warning: strpos() expects parameter 1 to be string, array given in /home2/wafg440adhss/public_html/wp-includes/shortcodes.php on line 205

Warning: preg_match_all() expects parameter 2 to be string, array given in /home2/wafg440adhss/public_html/wp-includes/shortcodes.php on line 213

Warning: array_intersect(): Argument #2 is not an array in /home2/wafg440adhss/public_html/wp-includes/shortcodes.php on line 214

This is the code I used in my theme file:

<?php echo do_shortcode([‘avatar_upload’]); ?>

This code is placed in my form-edit-account.php file within my theme which is in wp-content/themes/mytheme/woocommerce/myaccount folder. I figured that the place to put the code because when I am on the "my-account.php" generated page by WooCommerce, my theme makes a navigation and a page called "account details" that shows on the my-account.php and ultimate ends up being mydomain.com/my-account/edit-account when viewing live. Low and behold, I was right and it shows exactly where I want it to....but it shows the error!

The shortcode I am trying to pull is from the WP User Avatar plugin (free version, can be downloaded from the Wordpress plugins, add new and searching for it) so users can upload their own photo. The plugin says to use the following code to add it to a theme:

<?php do_action('edit_user_avatar', $current_user); ?>

but when I use that code, there is nothing to submit and save the avatar. When I use the shortcode on a page, it works perfectly and allows me to submit and save the avatar, but it can only be placed at the end of my woocommerce shortcode on the my-account page and it doesn't fall under the "account details" navigation and I dont likee it there. So since the shortcode funtions, I want to try to add the shortcode to the theme file vs the given php code, but I get that error.

Any help?

1
  • 1
    those quotes around ‘avatar_upload’ aren't proper single quotes, they're typographer quotes, or "curly" quotes. note how they differ from the single quotes in your second example.
    – Milo
    Commented Aug 11, 2017 at 5:00

1 Answer 1

2

Folowing on Milo's comment, do_shortcode expects the parameter to be exactly as if it is a shortcode inserted as part of the content, therefor your attempt to quote avatar_upload is just wrong and it should be do_shortcode('[avatar_upload]');

In addition it is probably better to just avoid using do_shortcode and call the relevant official API, if the plugin has one, directly, especially since shortcode might be processed differently based on context, in a way that might not match your needs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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