$ is not defined [duplicate]
WP loads jQuery in no conflict mode, so you can either swap $() for jQuery(), or wrap it in a function, e.g. (function($) { // Code using `$` … })(jQuery);
WP loads jQuery in no conflict mode, so you can either swap $() for jQuery(), or wrap it in a function, e.g. (function($) { // Code using `$` … })(jQuery);
I forgot to add a default case to the switch…case statement of my add_script_attributes function in the functions.php file. Sorry that I did not see this before. From my functions.php: function add_script_attributes($tag, $handle) { switch($handle) { case “Popper”: return str_replace(“src=”https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js””, “src=”https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js” integrity=’sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo’ crossorigin=’anonymous'”, $tag); case “Bootstrap”: return str_replace(“src=”https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js””, “src=”https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js” integrity=’sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI’ crossorigin=’anonymous'”, $tag); default: return $tag; … Read more
You’ve tagged your question correctly with wp_enqueue_script but it doesn’t appear in your code so you are probably missing the jQuery library and bootstrap by the looks of it. Try adding the following: add_action(‘wp_enqueue_scripts’, ‘wp_add_jquery’); function wp_add_jquery () { wp_register_script( ‘my_jquery’, ‘http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js’); // Add your other scripts here (bootstrap, etc.) }
Is there a way to change the value of $msg and send it back to the HTML? Your code is basically already doing that, but there are a few issues: Your AJAX JS (jQuery.ajax()) is not sending the POST data named site-choice to your AJAX PHP callback (users_details_callback()) which reads the data via $_POST[‘site-choice’]. Your … Read more
It is not right location.href = “#modal”; when you need to change hash you need to use window.location.hash=”modal” but you have another problem! You need to initialize your plugin and use its api Instead of this location.href = “#modal”; you need to use: var inst = jQuery(‘[data-remodal-id=modal]’).remodal(); inst.open()
I just made a wordpress plugin out of the jquery plugin, inserted shortcodes and changed the way of adding the images. This solved all mentioned issues.
What is the earliest Hook a Script can use?
I believe you should be able to use this: global $post; $page_slug = $post->post_name; Where $page_slug is the variable you’re looking for. This has a pretty good explanation of why that works: https://blog.wplauncher.com/get-current-page-slug-wordpress/
Well, just figured it out by using different search terms: https://stackoverflow.com/questions/10757671/how-to-remove-line-breaks-no-characters-from-the-string To remove HTML breaks from PHP returns (not actually called “line breaks” because they may get confused with the br tag) you’d have to use something like str_replace() with the \r and \n characters which are PHP breaks. In my case, this is what … Read more
You are making direct calls to a PHP file in your theme, this is why you have the problem. Because WordPress didn’t handle the request, your file did, none of WordPress is loaded, and none of the plugins. There are also lots of security issues with this approach. If you need to make an AJAX … Read more