ajax call in wordpress front end

You have to localize script by using wp_localize_script function. In the admin side ajaxurl is already available. But in front end you have to localize script to define ajaxurl. Example: wp_enqueue_script( ‘custom-ajax-request’, ‘/path/to/settings.js’, array( ‘jquery’ ) ); wp_localize_script( ‘custom-ajax-request’, ‘MyAjax’, array( ‘ajaxurl’ => admin_url( ‘admin-ajax.php’ ) ) );

How to include jQuery properly?

assuming you have enqueued everything ( script files and style files ) properly in your wordpress theme’s folder following would be ( just assume ) your theme files wp-content/themes/your-theme-dir/ assets/ css/ ( this is directory/folder ) styles.css ( this is file ) js/ scripts.js index.php functions.php lets say your code shown above is in index.php … Read more

Twitter Bootstrap Use Collapse in Custom Post Type

The script First you have to enqueue the script. We conditionally load it only for your custom post type and its archive(s). // in your functions.php function wpse69274_enqueue_tbs_collapse() { if ( ! is_post_type_archive() AND ‘YOUR_POST_TYPE’ !== get_post_type() ) return; wp_enqueue_script( ‘tbs-collapse’ ,get_stylesheet_directory_url().’path/to/your/collapse.js’; ,array( ‘jquery’ ) ,filemtime( get_stylesheet_directory().’path/to/your/collapse.js’ ) ,true ); } add_action( ‘wp_enqueue_scripts’, ‘wpse69274_enqueue_tbs_collapse’ ); … Read more

Querystring data gets truncated

As you have asked wether or not you have done the url encoding for the ampersands right, then my answer is: No. You are calling a javascript function, you’re not outputting something as x(ht)ml. You therefore do not need to encode & as &. The function is expecting a URL not a string that contains … Read more

Localize variable for multiple Shortcodes

Your ploblem is that wp_localize_script print to the html markup a javascript object similar to: var slider = {“id”:”a_unique_id_here”}; if you call it more times, e.g. using more shortcodes in same page, whati is printend in html markup is var slider = {“id”:”a_unique_id_here”}; var slider = {“id”:”another_unique_id_here”}; var slider = {“id”:”third_unique_id_here”}; so you are overwriting … Read more

possible to make sections in theme customizer sortable and saveable at publish button clicked?

Simple tutorial – How to sort customizer sections in the panel and add order to theme. 1. You must use prefixes to do this because customizer don’t support custom classes. ctmss_panel_ – for panels ctmss_section_ – for sections ctmss_hidden_ – for hidden sections that has a input with values 2. Add panel to the Customizer … Read more

Best approach for loading a sidebar Only if the screen max-width is >900px?

On my website I load the recent comments per AJAX for window sizes above 480px: if ( 480 < jQuery(window).width() ) { jQuery(document).ready( function() { jQuery.get(‘http://toscho.de/?rc’, function(data) { jQuery(data).insertBefore(‘#inner’); } ); } ); jQuery(‘#posts’).after(‘<div class=clear>&#160;</div>’); } This code is quite old and not very elegant. But it may give you a hint for the right … Read more

Unbind postbox click handler

You can just put the necessary javascript in a file and enqueue it on the necessary page: add_action( ‘admin_enqueue_scripts’, ‘add_admin_scripts’, 10, 1 ); function add_admin_scripts( $hook ) { //You can globalise $post here and enqueue the script for only certain post-types. if ( $hook == ‘post-new.php’ || $hook == ‘post.php’) { wp_register_script( ‘my_js_handle’,’/path/to/js/my-js-file.js’,array(‘jquery’),1,true); wp_enqueue_script(‘my_js_handle’); } … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)