New answers tagged

0

//use this to see what is the name of script. add this to functions.php global $wp_script; var_dump($wp_script); //now remove the script function wpdocs_dequeue_script() { wp_dequeue_script( 'google-maps' ); wp_deregister_script( 'google-maps' ); } add_action( 'wp_print_scripts', 'wpdocs_dequeue_script', 100 );


0

I faced the same problem when building my own Frontend Form. Here's how to solve it, form has the default tendenacy to submit itself and reload. We not to stop that and use AJAX to submit the data. A lot depends upon other functions to. But generally speaking this should work. $(".button").click(function(e) { e.preventDefault(); $('.error')...


0

When you enqueue a script with wp_enqueue_script() it adds the <script> tag part for you. If you have HTML that the script interacts with you will need to add that HTML to the page another way. You should not include the script tag in any HTML. There are many options for adding HTML to a page, depending on where you need it: Adding it in the Text tab ...


0

Here is my oun answer, hope some can someone help with this. I add a comments in code <script> //Now this windows.addEventListener, don't Work at All. I need some like this, when the user came back in other session or reload the page, The button, **still disabled** But i don't know how to make it work. PLEASE ANY HELP? window.addEventListener('...


4

As said on https://wordpress.org/support/article/debugging-in-wordpress/#example-wp-config-php-for-debugging: (note though, the "blogging" below is now "publishing") NOTE: You must insert this BEFORE /* That's all, stop editing! Happy blogging. */ in the wp-config.php file. So just put it there, like this: define( 'WP_DEBUG', true ); /*...


0

The solution above from Jordan Foreman makes sense and I first tried exactly the same thing, but it did not work for me. In fact, in the WordPress media-editor.js core file there is a return false on the #remove-post-thumbnail click event that I think it's being called before the document click and that could be preventing it to be triggered. $('#...


0

There are two errors I see in your code. First is that you've written get_stylesheet_directory_url() instead of get_stylesheet_directory_uri(). Switch the L for an I and that will probably fix it. Second, for the JS file you're adding a slash before the folder, and for the CSS you're not. Once you fix the URL/I issue, you may still need to remove the / ...


0

Just gather all the car's id into one array and pass it to compare page and fetch only those cars which have ids in compare car array.


2

That's not how <noscript> tags work, and if they did your usage is incorrect. The <noscript> tag defines an alternate content to be displayed to users that have disabled scripts in their browser or have a browser that doesn't support script. The <noscript> element can be used in both <head> and <body>. When used inside <head&...


0

One way to handle this with the approach you've taken is to expand on the PHP code for the check to see if the user is logged in like so: <?php if (!is_user_logged_in()) : ?> <style> .product-purchase-box{display: none;} .linktologin{display: inline;} </style> <?php else : ?> <style> .product-purchase-box{display: inline;} ...


0

Thanks @sallyCJ for fixing my error ! Here's some examples for WP-API backbone JS client. It may help others : Fetch post of a certain author and category : var filteredPosts = new wp.api.collections.Posts(); authorsPosts.fetch({ data: { author: currentUserId, categories: 42 } }).then( posts => { for(const post of posts){ //do stuff with each ...


0

Not sure if there's a specific reason that you'd want to use query strings, but it sounds like maybe localization could cover your needs. That would allow for your content to be translated depending on the user's location. I don't have too much experience with localization for WordPress specifically, but it looks like there's a ton of options as far as ...


1

This is happening because the entire comment edit page is inside a <form> element, and the <button> element submits any form that it belongs to. This is the normal behaviour of buttons in HTML. If you don't want a button to act as a submit button, you need to set the type attribute to button: <button class="ed_button button button-small&...


0

Ok, with many hours of debugging and I finally came to know why it was not working. So everything is supposed to work the way it should be but there was a minor mistake in my JavaScript. Previous JavaScript var counter = 1; document.getElementById('add_more_content_block').addEventListener('click', function(e) { e.preventDefault(); var editor_id = &...


0

If you're using IDs for is_page() you should pass them as integers, not strings. Otherwise WordPress is looking for pages with a slug of "3854", not a page with that ID. So instead of: if ( is_page( array( '3854', '253' ) ) ) {} Use: if ( is_page( array( 3854, 253 ) ) ) {}


0

Php is a server-side language. Meaning the code is executed and the user will receive the compiled html code. The only way to execute php code as user is through 'post' or 'get' requests. So essentially loading a new page. The only workaround is using ajax to load new php code dynamically. But it may also be that what you plan to do is possible to do with ...


0

If you're using the block editor, then you could create a custom block to contain the calculation form. Optionally you could register a custom shortcode to print out the form. Afterwards you would be able to display the form on any post / page by using the block or shortcode depending on which one you chose to write. In both cases you probably want to create ...


1

I came to this question almost 3 years late, but there is a better way of doing that now: WordPress recommends using wp_add_inline_script when you want to pass data between PHP and JS, you can read about it here Basically, what you will do, is changing your wp_localize_script function call in your code, for this: wp_add_inline_script('my-script-name', 'const ...


1

Just updating this answer for 2021. You'll want to be familiar with node and optionally yarn (personal preference, but you can usually sub npm run x for yarn x scripts). Initialize the folder with yarn init it'll step you through some questions. Typically, the project name will be the same as your plugin or theme name and the version will be the same as the ...


3

Look at your condition at the end: if ( $result == false ) { wp_send_json_success( 'Link has been created' ); } else { wp_send_json_error(); } wpdb::insert() returns false when there's an error, so you're only returning a success response when there's an error. You need to swap the statement around. if ( $result == false ) { wp_send_json_error();...


0

Is there a way to prevent user from entering script tag to the form? Yes, escaping. It is one of the fundamental cornerstones of web security, and completely missing from the code in the question. Take this example: <a href="<?php echo $foo; ?>"> How do we know it's actually a URL? Your colleague has said it should be a URL, but do ...


0

I also pulled my hair out... :) The scripts didn't load on one specific page, especially the scripts wp-media, which lead to the error "wp.media is not defined"... all the solutions didn't work. It turned out the content on this page was too massive, my PHP Memory Limit was to low. Setting up MemoryLimit 256->512 worked for me... Greetings ;)


Top 50 recent answers are included