DEV Community

Discussion on: Vue Application as a Wordpress Plugin

Collapse
 
dstearle profile image
Dallas Earle

Excellent article! I ended up using this to build a new map plugin which is coming along very nicely. Something I am struggling with is trying to figure out a way to get the proper paths for some things like images. Usually in WP I would use something like "<?php echo get_template_directory_uri(); ?>" to handle that but obviously I can not use a PHP function in my JS app.

I have read about wp_localize_script() which can allow you to pass the values of said PHP functions to JS but I have no idea how to get that to work with this type of set up since it is a plugin.

Any ideas?

Collapse
 
dgmann profile image
DGMANN • Edited

Hi Dallas Earle and thank you!
Is it possible for you to use the Wordpress API? If this is the case, maybe you can get your images from "demo.wp-api.org/wp-json/wp/v2/media"?

Collapse
 
dstearle profile image
Dallas Earle

Well I am currently using WP API to fetch data from custom posts but the images I need are stored in a folder in the Theme. Wouldnt the "/wp/v2/media" endpoint only be good to retrieve media from posts? I am pretty new to using WP so I am not entirely familar with how the WP API works yet.

Thread Thread
 
dgmann profile image
DGMANN

I'm sorry. I did not read that correctly.
If you know where the pictures are stored, can you access this folder in your Vue app?