Skip to content

Instantly share code, notes, and snippets.

@fukasawah
Last active March 6, 2016 14:49
Show Gist options
  • Save fukasawah/a752c5bde01fa5ea3fa0 to your computer and use it in GitHub Desktop.
Save fukasawah/a752c5bde01fa5ea3fa0 to your computer and use it in GitHub Desktop.
【WP】プレビュー画面に任意のJSやデータを送り込むサンプル
class aaaa{
public function __construct()
{
add_action('wp_head', array(
$this,'register_preview_header'
));
}
public function register_preview_header()
{
if (! is_preview()) {
return;
}
wp_enqueue_script('vue', plugins_url('js/vender-libs/vue.js', __FILE__));
wp_enqueue_script('preview-editor', plugins_url('js/preview-editor.js', __FILE__));
wp_localize_script('preview-editor', '_meta_post_data',
array('article' => array(
'description' => 'テスト'
)
));
}
}
if(undefined === _meta_post_data){ throw new Exception("_meta_post_data is not defined") } // check defined.
jQuery(function($){
var entryContentVue = new Vue({
el: 'article > .entry-content',
template: '<div>これはVueで書き換えたものです. {{article.description}}</div>',
data: _meta_post_data
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment