简体   繁体   English

我可以将完整的Google表单及其样式嵌入到我的Wordpress网站中吗?

[英]Can i embed the full google form in my wordpress website with its styles?

我尝试了很多方法来做到这一点,但是没有用,它总是没有样式就被嵌入,而且看起来甚至连js也很难看。

Here is a generic widget template that I made that might help you. 这是我制作的通用小部件模板,可能会对您有所帮助。 You just gotta fill in the missing pieces (html, css and js files) 您只需要填写缺失的部分(html,css和js文件)

<?php
/*
Plugin Name: General Widget 
Plugin URI: 
Description: 
Author:
Version: 1
Author URI:
*/
// register widget
add_action('widgets_init', create_function('', 'return register_widget("General_Widget");'));

class General_Widget extends WP_Widget {

// constructor
    function General_Widget() {
        // Give widget name here
        parent::WP_Widget(false, $name = __('General Widget', 'wp_widget_plugin'));

        // link the style sheet for the widget
        add_action( 'wp_enqueue_scripts', array($this,'add_styles'));  
        // link javascript file
        add_action( 'wp_enqueue_scripts', array($this,'add_scripts'));  
        // register the shortcode
        // TODO: 
        add_shortcode('INSERT SHORTCODE HERE', array($this, 'shortcode'));
    }

    // function that enqueues the necessary javascript files
    function add_scripts() {    
    // TODO:    
        // NOTE this is risky, might mess with your theme.
        wp_deregister_script( 'jquery' ); // we will use our own versions of jquery
        wp_deregister_script( 'jquery-migrate' );
        global $post;
        // only register and add scripts for this widget if the widget is active or if the post has a shortcode
        if(has_shortcode($post->post_content, 'INSERT SHORTCODE HERE') ||  is_active_widget( false, false, $this->id_base, true )) {
            // register the different scripts
            wp_register_script('jqueryMin', plugins_url('js/lib/jquery-2.2.4.min.js', __FILE__), array(), false, false); // https://developer.wordpress.org/reference/functions/wp_register_script/

            // add them to document
            wp_enqueue_script('jqueryMin');
        }
    }

    // enqueues the stylesheet
    function add_styles() {
        // TODO: 
        global $post;
        if(has_shortcode($post->post_content, 'INSERT SHORTCODE HERE') ||  is_active_widget( false, false, $this->id_base, true )) {
            // register the different style sheets
            wp_register_style('bootstrapMinStyle', plugins_url('css/lib/bootstrap.min.css', __FILE__), array(), false, "all"); // https://codex.wordpress.org/Function_Reference/wp_register_style
            wp_register_style('commonStyle', plugins_url('css/common.css', __FILE__), array(), false, "all"); // https://codex.wordpress.org/Function_Reference/wp_register_style
            $arrCoreStyles = array('bootstrapMinStyle', 'commonStyle');

            wp_register_style('quoteStyle', plugins_url('css/quote.css', __FILE__),$arrCoreStyles, false, "all"); // https://codex.wordpress.org/Function_Reference/wp_register_style
            // add style sheet and all of its dependencies
            wp_enqueue_style('quoteStyle');
        }
    }

// widget form creation. This handles the form that the wordpress admin sees when they add the widget to a widget area
    function form($instance) {
    }

    // updates the data stored in the widget when wordpress admin adds widget
    function update($new_instance, $old_instance) {
    }

    // gives the widget shortcode functionality
    function shortcode($atts) {
        $args = shortcode_atts( array(), $atts );
        $this->add_to_args($args);
        $this->display($args);
    }

// displays the widget to the client.
    function widget($args, $instance) {
        $this->add_to_args($args);
        $this->display($args);
    }

// use this to add fields to args before we display
    private function add_to_args(& $args) {
        // TODO: 
        $args['customWidgetHTML'] = "html/NAME OF HTML TEMPLATE.html"; 
    }

// this is an additional function, not inherited from WP_Widget. It is used for displaying html to
// client. Is called by both widget() and shortcode()
    private function display($args) {
        extract($args); 
        // TODO: 
        wp_enqueue_script('quoteJS'); // we dont want this in the header so we just enqueue it here
        echo $before_widget;
        include(plugin_dir_path(__FILE__) . $customWidgetHTML);
        echo $after_widget; 
    }
}
?>

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

相关问题 如何将网站嵌入 wordpress 页面? - How can I embed a website into a wordpress page? 我可以在我的wordpress网站中嵌入整个网站,以便在灯箱中显示该网站吗? - Can I embed a whole website in my wordpress site so that it shows in a lightbox? 我正在尝试使用 ajax 在我的 wordpress 网站上发送表格,但出现错误 500 - I'm trying to send a form on my wordpress website using ajax, but its an error 500 我可以在其他网站上嵌入WP用户注册表格吗? - Can I embed WP User Registration form on another website? 如何在Wordpress中将自定义样式覆盖到Useragent样式表? - How can i override my custom styles to useragent stylesheet in wordpress? 如何在WordPress中使Google表格完全嵌入宽度和高度? - How do I make embed google sheets full width and height in Wordpress? 在哪里可以在wordpress .php中找到文件,我可以在其中将Google字体链接到我的网站? - Where to find file in wordpress .php in which i can link google font to my website? 谷歌我的地图 ~ 嵌入到 wordpress 的自定义地图 - google my maps ~ custom map embed into wordpress 当我在Android应用程序中嵌入网站(wordpress博客)时,它是否在另一个浏览器中打开? - When I Embed a website (wordpress blog) on my android app it opens in another browser? 我无法在Wordpress网站上设置自定义菜单的样式 - I can't style my customized menu in my wordpress website
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM