Last active
June 13, 2018 13:08
-
-
Save smartdeal/e09e968898df33bc55877107ad6749fb to your computer and use it in GitHub Desktop.
[Способ подключения скриптов внутри шорткода] #WP #WP_functions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Для начала зарегистрируйте ваш JavaScript-файл без подключения | |
function mihdan_wp_enqueue_scripts() { | |
wp_register_script( 'script-name', plugins_url( '/js/script.js' , __FILE__ ), array(), '1.0.0', true ); | |
} | |
add_action( 'wp_enqueue_scripts', 'mihdan_wp_enqueue_scripts' ); | |
/* *************** */ | |
function mihdan_shortcode( $atts ) { | |
// Код вашего шорткода | |
... | |
// Подключение вашего скрипта по требованию | |
wp_enqueue_script( 'script-name' ); | |
} | |
add_shortcode( 'mihdan_shortcode', 'mihdan_shortcode' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment