I was working on a widget plugin for WordPress the other day and I was having trouble implementing the wp enqueue script function in the code below.
https://codex.wordpress.org/Function_Reference/wp_enqueue_script
/**
* Front-end display of widget.
*
* @see WP_Widget::widget()
*
* @param array $args Widget arguments.
* @param array $instance Saved values from database.
*/
public function widget( $args, $instance ) {
echo $args['before_widget'];
if ( ! empty( $instance['title'] ) ) {
echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'] ). $args['after_title'];
}
echo __( '<script type="text/javascript" src="https://d21djfthp4qopy.cloudfront.net/humanitybox.js "></script>', 'text_domain' );
echo $args['after_widget'];
}
I’ve been trying for hours, but I can’t get it to work. Below is a link to the Github project page.
I’m pretty new to writing plugins for WordPress, so more detail would be extremely helpful.
https://github.com/ModMarc/WordPress-Humanity-Box-Widget/blob/master/Widget.php
try this script it’s work