简体   繁体   English

WordPress插件以及如何从js文件获取?

[英]WordPress plugin and how to fetch from js-file?

I'm learning to building my own WordPress plugin and it nearly works. 我正在学习构建自己的WordPress插件,并且几乎可以正常工作。

Here's part of the code which I feel is the most relevant: (The plugin is supposed to create an splash screen on start where an Vimeo-clip is supposed to start playing automatically). 我觉得这是与代码最相关的部分:(该插件应该在启动时创建一个启动屏幕,而Vimeo-clip应该会自动开始播放)。

define( 'COLORBOX_VERSION', '1.4.24' );
define( 'BVSSP_VIMEO_VERSION', '1.0' );
define( 'BVSSP_CSS_VERSION', '1.0' );

add_action( 'wp_enqueue_scripts', 'bvssp_colorbox_js' );

add_action('wp_footer', 'bvssp_data_display');

function bvssp_colorbox_js() {
    wp_register_style( 'bvssp-style', plugins_url('/css/colorbox.css',__FILE__), array(), BVSSP_CSS_VERSION );
    wp_enqueue_style( 'bvssp-style' );
    wp_enqueue_script( 'jquery' );
    wp_register_script( 'bvssp-colorbox', plugins_url('/js/jquery.colorbox-min.js',__FILE__), array('jquery','jquery-ui-sortable'), COLORBOX_VERSION );
    wp_enqueue_script( 'bvssp-colorbox' );
    wp_register_script( 'bvssp-vimeo', plugins_url('/js/bvssp-vimeo.js',__FILE__), array('jquery','jquery-ui-sortable','bvssp-colorbox'), BVSSP_VIMEO_VERSION );
    wp_enqueue_script( 'bvssp-vimeo' );
}

function bvssp_data_display() {
    echo '<a style="display:none;" class="vimeo" href="http://player.vimeo.com/video/67189599?title=0&amp;byline=0&amp;portrait=0&amp;badge=0&amp;autoplay=1">vimeo</a>';
}

The problem I have is that the content found in the bvssp-vimeo.js is not executed. 我的问题是bvssp-vimeo.js中的内容未执行。 This is what's inside that file: 这是该文件内的内容:

<script>
    jQuery(document).ready(function($) {
        $(".vimeo").colorbox({iframe:true, innerWidth:800, innerHeight:709, open: true});
    });
</script>

If I paste the code in this file directly in the theme, everything works great. 如果我将代码直接粘贴到主题中的此文件中,则一切正常。 But I want to execute the JS-code from the file instead. 但是我想改为从文件执行JS代码。 How can I do this? 我怎样才能做到这一点?

Kind regards Johan (now very tired) :) 亲切的问候约翰(现在很累):)

don't use HTML tags in javascript files : 不要在javascript文件中使用HTML标签:

jQuery(function($) {
    $(".vimeo").colorbox({iframe:true, innerWidth:800, innerHeight:709, open: true});
});

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

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