Is placing stuff in page text edit window bad form?
Yes, it is typically considered bad form to do that. The only reason you might do that is if the script you are including will be used on the page you are editing and ONLY that page.
Yes, it is typically considered bad form to do that. The only reason you might do that is if the script you are including will be used on the page you are editing and ONLY that page.
Ajax url should be set to wp-admin/admin-ajax.php as ajax requests should be handled via wp-admin/admin-ajax in wordpress. if ajaxurl is not defined you can get it by defining html attribute data-url as data-url=”<?php echo get_admin_url().’admin-ajax.php’?>”. jQuery(document).ready(function($){ $(“#wp-submit”).on(‘click’,function(e){ e.preventDefault(); username = $(“#userName”).val(); password = $(“#passWord”).val(); ajaxurl = $(this).data(‘url’); $.ajax({ type: “POST”, url: ajaxurl, data : { … Read more
When enqueuing a script, you should state your script’s dependencies. In your case, it’s jQuery. Enqueue your script in the following way: wp_enqueue_script ( ‘my-plugin’, ‘path/to/the.js’, array( ‘jquery’ ) ); You may also want to ensure that your script IS loaded in the footer, by setting the last argument to true: wp_enqueue_script ( ‘my-plugin’, ‘path/to/the.js’, … Read more
You haven’t passed jquery as a dependency for your script, and you are using the dollar sign too, which is not directly supported in WordPress due to conflict. First, pass jQuery as a requirement while enqueuing your navigation.js: wp_enqueue_script( ‘themename-navigation’, get_template_directory_uri() . ‘/js/navigation.js’, array(‘jquery’), ‘20151215’, true ); Then, wrap your code in a self invoking … Read more
You can better try this way and let me know. function wpb_adding_scripts() { wp_enqueue_style( ‘slider’, get_stylesheet_directory_uri() . ‘/css/calculator.css’); wp_enqueue_script(‘jquery’); wp_enqueue_script(‘calculator_script’, get_stylesheet_directory_uri() . ‘/js/calculator.js’); } add_action( ‘wp_enqueue_scripts’, ‘wpb_adding_scripts’ );
This error means that the resource (JS file in this case) that you’re loading is expected to be JS and is instead HTML. It could be because your path is incorrect or because the local file is not JS. More than likely, your provided script at /assets/js/masonry-script.js is not a JS file or couldn’t be … Read more
The following will work for simple products and variable products with product variations. It requires jQuery to change the the add to cart button text depending on selected variation on variable products. I have revisited your initial code completely. // Conditional function that checks if a product is in cart and return the correct button … Read more
You can’t send the data to admin-ajax.php as JSON: data: JSON.stringify({ action: “process_coupon” }), For the wp_ajax_ actions to be fired, WordPress checks $_REQUEST[‘action’], but this is not populated by PHP when the form is submitted as JSON. The correct way to send the request with jQuery is to pass the data like this: data: … Read more
Hi @haha: ‘admin_init’ is definitely an\ workable way to load scripts but you might also want to take a look at this blog post and consider using the “admin_print_scripts-{$page}” hook instead which can allow you to only load on your page when you need it and not burden the other admin pages: How To: Load … Read more
Rather than modifying the template, since you’re going to need jQuery anyway, you can do this.. Add to the functions.php add_action( ‘wp_enqueue_scripts’, ‘blogroll_toggles’ ); function blogroll_toggles() { if( is_page_template( ‘bookmarks.php’ ) ) wp_enqueue_script( ‘blogroll-toggle’, get_bloginfo( ‘stylesheet_directory’ ) . ‘/blogroll-toggle.js’, array( ‘jquery’ ) ); } Or create a new folder in the wp-content/plugins/ folder, create a … Read more