简体   繁体   English

在Wordpress短代码中插入GoogleChart

[英]Inserting a GoogleChart in a Wordpress shortcode

I'm looking for a way to insert a GoogleChart in a Wordpress page. 我正在寻找一种在Wordpress页面中插入GoogleChart的方法。

I know that shortcode let you add HTML, but what about Javascript? 我知道短代码可以让您添加HTML,但是Javascript呢? Is this possible? 这可能吗?

Let's say I want to add the following example chart: https://developers.google.com/chart/interactive/docs/quick_start 假设我要添加以下示例图表: https : //developers.google.com/chart/interactive/docs/quick_start

How would I do that? 我该怎么做? I heard about some plugins that let you add Javascript code in Wordpress, but isn't there a way to do this natively? 我听说过一些插件,可以让您在Wordpress中添加Javascript代码,但是没有原生的方法吗?

Yes there is! 就在这里!

You'll need to place all those Javascript into its own file and use the theme's functions.php to enqueue the Javascript at the head. 您需要将所有这些Javascript放入自己的文件中,并使用主题的functions.php将Javascript排入队列。

Then inside the Wordpress, edit article as Text and write the div tag as plain HTML. 然后在Wordpress中,将文章编辑为“文本”,并将div标签编写为纯HTML。

You can also do it the shortcode way where the shortcode renders that div tag. 您也可以使用简码方式来实现,其中简码呈现div标签。 There is plenty of documentation online to go about this and it is easy to code it. 在线上有很多文档可以解决此问题,并且很容易编写代码。 Basically just having a function return that div when the shortcode is called. 基本上,只有一个函数在调用短代码时返回该div。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM