How do I add a php statement to a jQuery string

You might want to try to use wp_localize_script() to allow your javascript to use data that are normally only available using php. Here is the link in the codex that will help you do what you need: https://codex.wordpress.org/Function_Reference/wp_localize_script Another way is to use a php to output your entire javascript code (in a php file, … Read more

chosen jquery library not loading – is not a function error

You forgot to load chosen library: wp_register_script( ‘js_chosen’, ‘https://raw.github.com/harvesthq/chosen/master/chosen/chosen.jquery.js’, array(‘jquery’) ); wp_register_script( ‘js_custom’, plugin_dir_url( __FILE__ ) . ‘js/jquery.js’, array(‘jquery’, ‘js_chosen’) ); wp_enqueue_script ( ‘js_custom’ );

Using AJAX to return search form results

There are two issues in your code You need to add script in wp_enqueue_scripts hooks like this – add_action(‘wp_enqueue_scripts’, ‘my_custom_js_script’); function my_custom_js_script() { wp_register_script( ‘ajax-productSearch’, get_template_directory_uri() .’/js/ajax-product-search.js’, array( ‘jquery’) ); wp_enqueue_script( ‘ajax-productSearch’ ); wp_localize_script( ‘ajax-productSearch’,’the_ajax_productSearch’, array(‘ajaxurl_productSearch’ => admin_url(‘admin-ajax.php’))); } The second issue is that, you need to add action argument in your jQuery.ajax data. If … Read more

Hide pages from google and visitors

Add a simple checkbox to the post editor to toggle the generation of a meta field that disallows search engines to index your content. Then hook into wp_head, check for the setting and print that field. Sample code for a plugin: add_action( ‘post_submitbox_misc_actions’, ‘show_noindex_checkbox’ ); add_action( ‘save_post’, ‘save_noindex’, 10, 2 ); add_action( ‘wp_head’, ‘insert_noindex_meta’ ); … Read more

wp_enqueue_script won’t load in header?

Write wp_enqueue_script in wp_enqueue_scripts action function load_kenburns() { if ( !is_admin() ) { wp_register_script( ‘kenburns’, get_template_directory_uri() . ‘/js/bannerscollection_kenburns.js’, ”, ”, false); wp_register_script( ‘jquery-ui’, get_template_directory_uri() . ‘/js/jquery-ui-1.8.16.custom.min.js’, ”, ”, false); wp_register_script( ‘jquery-touch’, get_template_directory_uri() . ‘/js/jquery.ui.touch-punch.min.js’, ”, ”, false); wp_register_script( ‘kbsettings’, get_template_directory_uri() . ‘/js/kenburnsettings.js’, ”, ”, false); wp_enqueue_script( ‘kbsettings’ ); wp_enqueue_script( ‘kenburns’ ); wp_enqueue_script( ‘jquery-ui’ ); wp_enqueue_script( … Read more

How to Change CSS Variable value in Theme Customizer Live Preview

Quick Note: It looks like you may want to use a Color Control instead of excluding type and getting the default text control. For example, this will turn your text input into a color picker… $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, ‘primary_color’, [ ‘label’ => __( ‘Primary Color’, ‘mytheme’ ), ‘section’ => ‘mytheme_color_options’, ‘type’ => ‘color’ ] … Read more

How to save the checked boxes?

You can use PHP in your functions.php file to insert inline JavaScript (including jQuery) using WordPress hooks. In your example, you could use the admin_print_scripts-post.php action hook to print your inline jQuery like so: function wpse_admin_print_scripts_edit() { echo “<script>var limit = 2;’ . ‘jQuery(‘input.single-checkbox’).on(‘change’, function(evt) {‘ . ‘if(jQuery(‘input.single-checkbox:checked’).length > limit) {‘ . ‘this.checked = false;’ … Read more