create_function is deprecated

code php wordpress

Php function ‘create_function‘ has been deprecated as of PHP 7.2.0. So, while initializing widget I used to do this, add_action( ‘widgets_init’, create_function( ”, ‘register_widget(“Widget_Name”);’ ) ); Now, replacing deprecated function, add_action( ‘widgets_init’, function() { register_widget( ‘Widget_Name’ ); } );  

Creating Shortcode

// [shortcode_name] add_shortcode( ‘shortcode_name’, ‘your_shortode_function’ ); function your_shortode_function( $atts ) { return “name = { $atts[‘name’] }”; }   Simple Shortcode Example

Using .js and .css file with WordPress

WordPress function used to register, enqueue and localize javascript and css files. add_action( ‘init’, ‘register_script_style’ ); function register_script_style() { wp_register_style( ‘your_style_name’, $url_to_your_css_folder . ‘/your-style.css’, array(), $version ); wp_register_script( ‘your_script_name’, $url_to_your_js_folder . ‘/your-script.js’, array( ‘jquery’ ), $version, true ); wp_enqueue_script( ‘your_script_name’ ); wp_enqueue_style( ‘your_style_name’ ); //Localize your script $params = array( ‘ajaxurl’ => admin_url( ‘admin-ajax.php’ ), … Read more

Quick Way of using AJAX in WordPress

This is a quick template that I repeatedly use while working with AJAX in WordPress.   In .js $(‘body’).on(‘click’, ‘.some_element_class’, function (e) { e.preventDefault(); var ajaxdata = {}; //Data that you’re sending ajaxdata.somedata = ‘somedata’; ajaxdata.action = ‘your_action_name’; $.ajax({ beforeSend: function () { //some work before sending data }, type: ‘POST’, dataType: ‘json’, url: ajaxscript.ajax_url, … Read more

WordPress Debug Function

WordPress easy debugging function, Function that I use most of the time while printing out the output. This function is used specially when output are processed in background and print function will not display outputs. Then this function will comes handy which will log the output. Now we can check debug log to see what … Read more