SmoothScroll not working in WordPress

Thanks to CSS Tricks, I changed the existing SmoothScroll code that came with the site to the following which worked: $(function() { $(‘a[href*=#]:not([href=#])’).click(function() { if (location.pathname.replace(/^\//,”) == this.pathname.replace(/^\//,”) && location.hostname == this.hostname) { var target = $(this.hash); target = target.length ? target : $(‘[name=” + this.hash.slice(1) +”]’); if (target.length) { $(‘html,body’).animate({ scrollTop: target.offset().top }, 1000); … Read more

No data received

Your code is wrong. You are confusing wp_enqeue_script function and wp_enqueue_scripts action. It should be: function theme_script(){ wp_deregister_script( ‘jquery’ ); wp_register_script(‘jquery’,get_template_directory_uri().’/sliderengine/jquery.js’); wp_enqueue_script(‘jquery’); wp_register_script(‘amazingslider’,get_template_directory_uri().’/sliderengine/amazingslider.js’,array(‘jquery’)); wp_enqueue_script(‘amazingslider’); wp_register_script(‘initslider-1′,get_template_directory_uri().’/sliderengine/initslider-1.js’,array(‘jquery’)); wp_enqueue_script(‘initslider-1’); } add_action(‘wp_enqueue_scripts’,’theme_script’);

Correct way to write jQuery functions in WordPress

As suggested in comments, this kind of error is caused by the fact that WordPress loads jquery in noconflict mode. The most common workaround is to wrap all functions in your script file: jQuery(document).ready(function($) { … scripts … } Another, more risky option is to switch off noconflict mode by starting the script file with … Read more

Front-end Ajax File Upload

I use this code to upload if ( ! function_exists( ‘wp_handle_upload’ ) ) { require_once( ABSPATH . ‘wp-admin/includes/file.php’ ); } if($_FILES[‘file’][‘name’] != ”) { $uploadedfile = $_FILES[‘file’]; $upload_overrides = array( ‘test_form’ => false ); $movefile = wp_handle_upload( $uploadedfile, $upload_overrides ); if ( $movefile && ! isset( $movefile[‘error’] ) ) { $file_url = $movefile[‘url’]; $file_url = … Read more

How to get those data using with ajax json?

There are two methods to access the object. 1. Ajax response. $.ajax({ url:”your_file.php”, type : “POST”, data : your_data, dataType: “json”, success:function(data){ // Retrieve the object var result = data[0]; // Grab username from the object console.log(result[‘username’]); }, error:function(xhr){ alert(‘Ajax request fail’); } }); 2. Server side script $yourArray = array(); $yourJson = json_encode($yourArray); $userData … Read more

Use Media Uploader on Multiple Images on same page

So I set a new variable of target_input that grabs the previous input field ID, this input is where I want the URL of the selected media stored, this is done in the click function of the button that selects the media. That variable is used to attach the URL. jQuery(document).ready(function($){ var custom_uploader; var target_input; … Read more

Reorder displayed posts with JQuery (title A-Z / last posted)

With WordPress you can utilise a function called wp_localize_script() which allows you to pass in a script, and a variable you would like that script to have access too. Perhaps by assigning the new query to a variable, and then accessing it within jQuery would help you solve your problem. The example provided by WordPress … Read more

Getting all URLs of uploaded images using media uploader

Got it working with a code from this question https://stackoverflow.com/questions/14847668/get-url-of-freshly-uploaded-image-from-wp3-5-media-uploader Maybe somebody will find it useful. This code logs URL of every freshly uplaoded image to console. jQuery(document).ready(function($){ $(‘#upload-btn’).click(function(e) { e.preventDefault(); var image = wp.media({ title: ‘Nahranie obsahu’, // mutiple: true if you want to upload multiple files at once multiple: true }).open() .on(‘select’, function(e){ … Read more