DEV Community

Discussion on: Using Vue in WordPress

Collapse
 
workingwebsites profile image
Lisa Armstrong • Edited

Good question!

I think your best approach would be to set up a component, and pass the the_title(); etc. in as a prop (variable).

See: vuejs.org/v2/guide/components.html
This will guide you through making a component.

Passing props (variables into your components):
vuejs.org/v2/guide/components.html...

In the end, you'd end up with something like..
in vuecode.js

Vue.component('wp-vue-title', {
  props: ['title'],
  template: '<h3>{{ title }}</h3>'
})
Enter fullscreen mode Exit fullscreen mode

In your template:

<wp-vue-title title="<?php the_title(); ?> "></wp-vue-title>
Enter fullscreen mode Exit fullscreen mode

Note: In the example tutorial, it adds a shortcode.

In your case, you probably wouldn't need it, since it sounds like you're doing this through the template. Shortcodes work better on the text side.

Good luck!