PHP
enqueue wordpress
function wpdocs_theme_name_scripts() {
wp_enqueue_style( 'style-name', get_stylesheet_uri() ); /* enqueues style.css */
/* if you want to enqueue other styles use: */
/* wp_enqueue_style( 'style-name', get_template_directory_uri() . '/css/your-style-name.css' ); */
wp_enqueue_script( 'script-name', get_template_directory_uri() . '/js/example.js', array(), '1.0.0', true );
}
add_action( 'wp_enqueue_scripts', 'wpdocs_theme_name_scripts' );
wordpress enqueue scripts and styles
/**
* Proper way to enqueue scripts and styles
*/
function wpdocs_theme_name_scripts() {
wp_enqueue_style( 'style-name', get_stylesheet_uri() );
wp_enqueue_script( 'script-name', get_template_directory_uri() . '/js/example.js', array(), '1.0.0', true );
}
add_action( 'wp_enqueue_scripts', 'wpdocs_theme_name_scripts' );
how to add js to wordpress with wp_enqueue_scripts
function ti_custom_javascript() {
wp_enqueue_script( 'example-script', get_template_directory_uri() . '/js/examplescript.js');
}
add_action('wp_enqueue_scripts', 'ti_custom_javascript');
wordpress enqueue jquery
add_action('wp_enqueue_scripts', 'my_register_script_method');
function my_register_script_method () {
wp_register_script( 'jqueryexample', 'https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js');
}
enqueue wordpress
function my_scripts_method() {
wp_enqueue_script(
'custom-script',
get_stylesheet_directory_uri() . '/js/custom_script.js',
array( 'jquery' )
);
}
add_action( 'wp_enqueue_scripts', 'my_scripts_method' );
wordpress enqueue js
add_action( 'wp_enqueue_scripts', 'my_plugin_assets' );
function my_plugin_assets() {
wp_enqueue_style( 'custom-gallery', plugins_url( '/css/gallery.css' , __FILE__ ) );
wp_enqueue_script( 'custom-gallery', plugins_url( '/js/gallery.js' , __FILE__ ) );
}
wordpress enqueue script on page
function my_enqueue_stuff() {
if ( is_page( 'landing-page-template-one' ) ) {
/** Call landing-page-template-one enqueue */
} else {
/** Call regular enqueue */
}
}
add_action( 'wp_enqueue_scripts', 'my_enqueue_stuff' );
enqueuing javascript in wordpress
function mysofthunt_enqueue() {
wp_enqueue_script(
'softhunt-script',
plugins_url( 'softhunt.js', __FILE__ )
);
}
add_action( 'enqueue_block_editor_assets', 'mysofthunt_enqueue' );