How do I activate jQuery/script on demand?

1. Register jQuery and the plugin within your head wp_register_script( ‘jquery’ ); wp_register_script( ‘your_jquery_plugin’, STYLESHEETPATH, ‘jquery’, ‘0.0’, false ); 2. Register a meta box It should be a simple checkbox. Please do it like it’s described on the codex page for add_meta_box() (don’t just repeat this one here). If you follow the rest, then the … Read more

Adding Scripts in the Admin Area

Instead of hooking into admin_print_scripts only, you should hook into your specific page slug which is appended to admin_print_scripts-. (note trailing hyphen). The reference page you linked to shows this, but you seem to be omitting the $page concatenation to admin_print_scripts-. eg: $page = add_theme_page( ‘Options’, ‘Options’, ‘edit_theme_options’, ‘options-panel’, ‘topf_admin_options_markup’ ); add_action( “admin_print_scripts-$page”, ‘enqueue_my_admin_scripts’ ); … Read more

WordPress Script Loading/Unloading — wp_deregister_script(‘jquery’)

WordPress has essentially two groups of methods to handle scripts, both of which should be used: wp_register_script Registers a script in WordPress. It does not get called, it is just available for WordPress, if it is needed. wp_deregister_script is the exact opposite. It deletes the definitions made in wp_register_script, the script is no longer available … Read more

Execute only on a certain page

The is_page function accepts any of the page ID, the page title or the page slug. It looks like you’re trying to give it an URL fragment instead. You say that ‘contact-us’ is the page slug for your contact page, so try if (is_page(‘contact-us’)) { without the forward slashes, i.e. passing the page slug, instead.

dequeue not work

Scripts should be enqueued on wp_enqueue_scripts action hook, which runs after init action. So dequeuing on init won’t work because sripts are not enqueued yet. Before enqueued scripts are printed, wp_print_scripts action is triggered so you can dequeue or unregister scripts safely at this moment: add_action( ‘wp_print_scripts’, ‘drw_timelinr_dequeue’ ); function drw_timelinr_dequeue () { wp_dequeue_script(‘jquery.timelinr’); } … Read more

Enqueued Stylesheets Effecting Admin Styles

You could do it like this: function theme_styles(){ /* * This if() statement is unnecessary, as wp_enqueue_scripts * doesn’t fire on the admin pages. * if( is_admin() ) { * return; * } */ wp_enqueue_style( ‘theme-styles’, get_template_directory_uri() . ‘/css/all.css’, array(), false, ‘all’ ); } add_action( ‘wp_enqueue_scripts’, ‘theme_styles’ ); References is_admin() Also, note that the wp_enqueue_scripts … Read more

Enqueue script o style only if a template part is loaded

You can use the get_template_part_{$slug} hook, which fires before a template part is loaded. You can find the reference here, which I find more useful than the official reference. So, I tested it in the twentytwentyone theme (yes I modified the theme directly but only for testing). I tested it with the template-parts/content/content-single.php part, and … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)