Using google graph api with wordpress

You should run updatepage() function after loading the google jsapi script. try jquery ready inside updatepage like this: function updatepage(){ // this line added by me jQuery(document).ready(function ($) { // Load the Visualization API and the piechart package. …. …. chart.draw(data, options); } } or you can see this shortcode code plugin for simple chart … Read more

Accessing customizer values in javascript

Given a setting with an ID of “foo” you can obtain the value via: var value = wp.customize( ‘foo’ ).get() To ensure that the setting is registered before you attempt to get its value, you can use this deferred pattern: wp.customize( ‘foo’, function( setting ) { var value = setting.get(); // … }); This should … Read more

How to set translations in javascripts for my plugin?

The WordPress way to do this is the wp_localize_script() function. When you enqueue a script, also add a call to wp_localize_script(): wp_register_script( ‘my-script’, ‘path/to/script.js’ ); wp_localize_script( ‘my-script’, ‘myScript’, array( ‘msg_must_match’ => __( ‘Message must match’, ‘my-plugin-domain’ ), ) ); This creates a global JavaScript object called myScript that will contain the keys and values passed … Read more

How to place script in footer?

If you want to output a single line of javascript, you might not need to put it in a js file and go through enqueuing it and stuff. Simply output it by using the wp_footer() action hook: add_action(‘wp_footer’,’print_my_script’); function print_my_script(){ echo ‘<script> // Your script here </script>’; } However, this is good just for small … Read more

var is undefined in a Gutenberg block

I think you have to pass in menu_selected edit: withAPIData( ( props ) => { return { menu_selected: `/menus/v1/menus/${ props.attributes.menu }` // custom endpoint }; } ) ( ( { menu_selected } ) => { I was able to do a very similar thing like so: edit: withAPIData( () => { return { posts: ‘/wp/v2/images?per_page=4&_embed’ … Read more

WP REST API Post Status Using JavaScript

In this tutorial, the post var status=”draft”; (see code). So I am just worried that won’t anyone able to hack that status? It depends who it is. A logged out user cannot create any posts at all. A subscriber cannot either. A contributor could create the post, but not publish it. An author or editor … Read more