lyzs90 / vuewp

VueJs Wordpress Theme
106 stars 24 forks source link

wp_head and wp_footer action hooks aren't triggered in headless setup #12

Open leoauri opened 6 years ago

leoauri commented 6 years ago

I'm still trying to follow everything here, but it seems that when served as WP theme we load index.php, so action hooks in header.php and so on are triggered, but when served headlessly we load index.html... No WP action hooks...

Actually I noticed when modifying index.php, wondering why nothing was changing :)

  1. Is index.html (the one in themes/vuewp, not in dist) generated somewhere along the way, based on the php files? Can we regenerate it if we need?
  2. Could we use HtmlWebpackPlugin based off of index.php, get rid of index.html altogether? Currently changes have to be made in two places if expected to reflect in both theme and headless setup...

Sorry if I'm still missing something... And thanks 👍👍

lyzs90 commented 6 years ago

@leoauri when serving headlessly, the vue app will be completely decoupled from the wordpress server. i.e. the wp-content/themes/vuewp/app/dist directory is served. all interactions between the frontend and the wordpress server happens solely via REST api. For action hooks, you might want check out https://v2.wp-api.org/extending/hooks/

to answer your questions:

  1. index.html is not generated based on index.php
  2. completely agree, it's unfortunate that changes have to be made in two places now. i'm not sure if HtmlWebpackPlugin allows this. Do have a look into this if you have the time, I would appreciate the PR :)