EvanAgee / vuejs-wordpress-theme-starter

A WordPress theme with the guts ripped out and replaced with Vue.
https://vuewp.com/
1.6k stars 281 forks source link

Shortcodes not working ? #130

Closed SSCombined closed 3 years ago

SSCombined commented 3 years ago

Anyone know if you can use shortcodes from custom plugins ?

I can't test them on pages because they won't work at all for me.

Posts do work however, but when I try to use a shortcode I'm getting the following error.

afbeelding

Any ideas ?

harrisonfm commented 3 years ago

https://developer.wordpress.org/reference/functions/do_shortcode/

You are executing your shortcodes in PHP, right?

SSCombined commented 3 years ago

https://developer.wordpress.org/reference/functions/do_shortcode/

You are executing your shortcodes in PHP, right?

I actually just found out what is causing this issue, but I'm not sure how to resolve it. 1) First of all my Pages are being handled as Posts.

2) So apparently the wordpress API needs to return an object from what I see from examples. For example if I grab a random wordpress website and do the following: https://wpdemo.net/wp-json/wp/v2/pages?slug=home It returns a full object with all the page data.

However if I do something like that I get the following No object or anything, just the HTML of the page I'm calling only.

afbeelding

Not sure how to fix this since I get the same results on every fresh WP installation.

harrisonfm commented 3 years ago

I'm not really sure what you're asking. Are you saying that your pages are being routed as posts in Vue? If so, that's easy to fix in the Router.

Are you not happy with the default returns from WP REST API? You can overwrite those and get your data however you need. getPostWithShortcodes for example.

SSCombined commented 3 years ago

I'm super stupid apparently. What I did in my custom shortcodes was

$shortcode_template = PLUGIN_PATH . 'public/partials/customers/blocks/customer.php';
include_once($shortcode_template);

This caused my page to mess up completely

I changed it to this.

$shortcode_template = PLUGIN_PATH . 'public/partials/customers/blocks/customer.php';
ob_start();
include_once($shortcode_template);
$content = ob_get_clean();
return $content;

And now my json is outputting correctly. This was an issue on my end.