'Is there any way i can load my inline and external scripts in WordPress plugin for AMP site?
I got stuck on loading scripts in amp sites (WordPress). I have built a custom plugin and it's working fine in WordPress but in mobile amp view, the scripts are not loading.
// Script
if (! function_exists('wp_text_counter_enqueue_scripts')) :
function wp_text_counter_enqueue_scripts()
{
global $post;
if ((is_single() || is_page()) && has_shortcode($post->post_content, 'wp-text-counter')) {
wp_enqueue_script('sachinkiranti-textual', 'https://unpkg.com/@sachinkiranti/[email protected]/dist/textual.min.js');
wp_enqueue_script('wtc-script', plugin_dir_url(__FILE__) . 'assets/wp-text-counter.js', array('jquery', 'sachinkiranti-textual'), null, true);
wp_enqueue_script('wphg-script', plugin_dir_url(__FILE__) . 'assets/wphg.js', array('jquery'), null, true);
wp_localize_script('wphg-script', "wphg_data", array(
'ajaxurl' => admin_url('admin-ajax.php'),
'action' => 'xxxx'
));
}
}
endif;
add_action( 'wp_enqueue_scripts', 'wp_text_counter_enqueue_scripts' );
How do I load these scripts? An example of both inline and external scripts would be a great help.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|