如何将javascript文件添加到我的wordpress插件?
我想在我的wordpress插件中集成一个共享按钮,我知道有很多插件可以做到这一点,但我只想在特定页面的末尾添加一个按钮 我把它添加到我的控制器中,这个控制器加载/注册其余的Java脚本,但它不起作用 这是我的控制器代码如何将javascript文件添加到我的wordpress插件?,javascript,jquery,wordpress,Javascript,Jquery,Wordpress,我想在我的wordpress插件中集成一个共享按钮,我知道有很多插件可以做到这一点,但我只想在特定页面的末尾添加一个按钮 我把它添加到我的控制器中,这个控制器加载/注册其余的Java脚本,但它不起作用 这是我的控制器代码 wp_enqueue_script( 'wpProQuiz_front_javascript', plugins_url('js/wpProQuiz_front' . (WPPROQUIZ_DEV ? '' : '
wp_enqueue_script(
'wpProQuiz_front_javascript',
plugins_url('js/wpProQuiz_front' . (WPPROQUIZ_DEV ? '' : '.min') . '.js', WPPROQUIZ_FILE),
array('jquery-ui-sortable'),
WPPROQUIZ_VERSION,
$footer
);
wp_register_script( //this is the js file I am registering
'share_button_javascript',
plugins_url('js/shareButton.js', __FILE__)
);
//wp_enqueue_script('share_button_javascript');
wp_localize_script('wpProQuiz_front_javascript', 'WpProQuizGlobal', array(
'ajaxurl' => admin_url('admin-ajax.php'),
'loadData' => __('Loading', 'wp-pro-quiz'),
'questionNotSolved' => __('You must answer this question.', 'wp-pro-quiz'),
'questionsNotSolved' => __('You must answer all questions before you can completed the quiz.',
'wp-pro-quiz'),
'fieldsNotFilled' => __('All fields have to be filled.', 'wp-pro-quiz')
));
<script>var shareButton = new ShareButton()</script>
<sharebutton>Share</sharebutton>
这是同一控制器视图中的代码
wp_enqueue_script(
'wpProQuiz_front_javascript',
plugins_url('js/wpProQuiz_front' . (WPPROQUIZ_DEV ? '' : '.min') . '.js', WPPROQUIZ_FILE),
array('jquery-ui-sortable'),
WPPROQUIZ_VERSION,
$footer
);
wp_register_script( //this is the js file I am registering
'share_button_javascript',
plugins_url('js/shareButton.js', __FILE__)
);
//wp_enqueue_script('share_button_javascript');
wp_localize_script('wpProQuiz_front_javascript', 'WpProQuizGlobal', array(
'ajaxurl' => admin_url('admin-ajax.php'),
'loadData' => __('Loading', 'wp-pro-quiz'),
'questionNotSolved' => __('You must answer this question.', 'wp-pro-quiz'),
'questionsNotSolved' => __('You must answer all questions before you can completed the quiz.',
'wp-pro-quiz'),
'fieldsNotFilled' => __('All fields have to be filled.', 'wp-pro-quiz')
));
<script>var shareButton = new ShareButton()</script>
<sharebutton>Share</sharebutton>
var shareButton=new shareButton()
分享
有人能告诉我我做错了什么吗?这样做:
wp_enqueue_script(
'wpProQuiz_front_javascript',
plugins_url('js/wpProQuiz_front' . (WPPROQUIZ_DEV ? '' : '.min') . '.js', WPPROQUIZ_FILE),
array('jquery-ui-sortable'),
WPPROQUIZ_VERSION,
$footer
);
//this is the js file You are registering
wp_register_script('share_button_javascript', plugins_url('js/shareButton.js', __FILE__), array('jquery'), '', true);
wp_enqueue_script('share_button_javascript');
//wp_enqueue_script('share_button_javascript');
wp_localize_script('wpProQuiz_front_javascript', 'WpProQuizGlobal', array(
'ajaxurl' => admin_url('admin-ajax.php'),
'loadData' => __('Loading', 'wp-pro-quiz'),
'questionNotSolved' => __('You must answer this question.', 'wp-pro-quiz'),
'questionsNotSolved' => __('You must answer all questions before you can completed the quiz.',
'wp-pro-quiz'),
'fieldsNotFilled' => __('All fields have to be filled.', 'wp-pro-quiz')
));
为什么OP要“试试这个”?一个好的答案总是会有一个解释,说明做了什么以及为什么这样做,不仅是为了OP,而且是为了未来的访客。