Posts

Showing posts from 2015

How to disable scroll effect in map html using css and jquery

Below is a sample of code for disable scroll on mouse scroll <style>     .scrolloff {         pointer-events: none;     } </style> <div id="googlemap" class="map">     <iframe id="gmap" src="https://www.google.com/maps/embed/v1/place?key=AIzaSyCjUE83FHrXTQWf9umcNDzyu0s7aNzHszw     &q=Space+Needle,Seattle+WA" width="100%" height="500" frameborder="0" ></iframe> </div> <script>     $(document).ready(function () {         $('#gmap').addClass('scrolloff');                               $('#googlemap').on("mouseup",function(){                     $('#gmap').addClass('scrolloff');                     });         $('#googlemap').on("mousedown",function(){                    $('#gmap').removeClass('scrolloff');         });         $("#gmap").mouseleave(function () {                  

How to allow custom shortcodes in custom widgets or in widgets in wordpress

For allow shortcodes in widgets we need to add 2 filters for render shortcodes. 1). Add below filter for remove auto p tag for widget area.. So our shortcode output will not wrapped by p tag   add_filter( 'widget_text', 'shortcode_unautop');  2) .Below filter will allow widget text to rendor shortcode add_filter( 'widget_text', 'do_shortcode', 11);

How to add a custom menu properties in menu item in wordpress

For add a custom menu properties in menu item just copy and paste below code into your theme's functions.php file or into your custom plugin file and do field's changes according to your need. Here i add a custom menu icon option for menu item. add_filter( 'wp_setup_nav_menu_item', 'rj_add_custom_nav_fields' );         // save menu custom fields add_action( 'wp_update_nav_menu_item',  'rj_update_custom_nav_fields', 10, 3 ); // edit menu walker add_filter( 'wp_edit_nav_menu_walker',  'rj_edit_walker', 10, 2 ); function rj_add_custom_nav_fields( $menu_item ) {             $menu_item->icon = get_post_meta( $menu_item->ID, '_menu_item_icon', true );         return $menu_item; } function rj_update_custom_nav_fields( $menu_id, $menu_item_db_id, $args ) {      // Check if element is properly sent         if ( is_array( $_REQUEST['menu-item-icon']) ) {             $icon_value = $_REQUEST['menu-item-icon'

How to backup wordpress database without phpmyadmin using php code

Just copy below code and run this code to take a backup of your website . <?php require 'wp-load.php'; global $wpdb;         $tables = $wpdb->get_results( 'SHOW TABLES', ARRAY_N );         $return = '';         foreach ( $tables as $table ) {             $num_fields = sizeof( $wpdb->get_results( 'DESCRIBE `' . $table[0] . '`;' ) );             $return .= 'DROP TABLE IF EXISTS `' . $table[0] . '`;';             $row2 = $wpdb->get_row( 'SHOW CREATE TABLE `' . $table[0] . '`;', ARRAY_N );             $return .= PHP_EOL . PHP_EOL . $row2[1] . ";" . PHP_EOL . PHP_EOL;                             $result = $wpdb->get_results( 'SELECT * FROM `' . $table[0] . '`;', ARRAY_N );                 foreach ( $result as $row ) {                     $return .= 'INSERT INTO `' . $table[0] . '` VALUES(';                     for ( $j = 0; $j < $num_fields; $j ++ ) {       

How to take a screenshot or make a image of current screen using php and javascript with jquery or make a pdf file of current scrren

For create a image of current screen using javascript add below script into your file <script type="text/javascript"> function printDiv() {     jQuery('.year_box').remove(); // add your container id for capcture screen here i write "main_panel_body" for example     html2canvas([document.getElementById('main_panel_body')], {           onrendered: function(canvas)          {             var img = canvas.toDataURL();             jQuery('.overlay_box').show(); // calling ajax method for create image from binary data             $.post("save.php", {data: img}, function (file) {                 jQuery('.overlay_box').hide();             window.open("download.php?business_idsv="+business_id+"&limit="+limit+"&path="+ file,'_blank');});           }     });     jQuery('.year_box').show();         } </script> Here is my save.php file require_once("config.

How to use ajax without jquery with pure javascript

Here is a snippet code for ajax request.. var ajax = {}; ajax.x = function() {     if (typeof XMLHttpRequest !== 'undefined') {         return new XMLHttpRequest();     }     var versions = [         "MSXML2.XmlHttp.6.0",         "MSXML2.XmlHttp.5.0",          "MSXML2.XmlHttp.4.0",         "MSXML2.XmlHttp.3.0",          "MSXML2.XmlHttp.2.0",         "Microsoft.XmlHttp"     ];     var xhr;     for(var i = 0; i < versions.length; i++) {         try {             xhr = new ActiveXObject(versions[i]);             break;         } catch (e) {         }     }     return xhr; }; ajax.send = function(url, callback, method, data, sync) {     var x = ajax.x();     x.open(method, url, sync);     x.onreadystatechange = function() {         if (x.readyState == 4) {             callback(x.responseText)         }     };     if (method == 'POST') {         x.setRequestHeader('Content-type', 'application/x-www

How to upload image to another server like amazon etc using php CURL

For upload an image or any file to external server using php curl just refer below code. and change it according to your need. $profile_image_string = '';             if ( isset($_FILES['profile_image']) )             {                 $tmpfile = $_FILES['profile_image']['tmp_name'];                 $filename = basename($_FILES['profile_image']['name']);                 $filetype = $_FILES['profile_image']['type'];                 $org_image_string =curl_file_create($tmpfile,$filetype,$filename);             }     $ch = curl_init();                  $data = array('user_id'=>$_SESSION['student_id'],'firstname'=>$user_name,'gender'=>$gender,                             'user_profile_pic'=> $org_image_string);                  //echo $url = "server url for upload data";                  $header = array('Content-Type: multipart/form-data');             

How to add a custom or new order status in woocommerce wordpress

For add a custom or new order status in woocommerce store. just copy and paste below code into your theme's functions.php or in your custom plugins file. For example i am add a shipping order status for order . // register post status wc-shipping add_action('init','register_shipping_post_status'); function register_shipping_post_status(){         register_post_status( 'wc-shipping', array(             'label'                     => 'Shipping',             'public'                    => true,             'exclude_from_search'       => false,             'show_in_admin_all_list'    => true,             'show_in_admin_status_list' => true,             'label_count'               => _n_noop( 'Shipping <span class="count">(%s)</span>', 'Shipping <span class="count">(%s)</span>' )         ) );     } Now for add a shipping s

How to allow html tags in the_excerpt post function in wordpress

Just copy and paste below code into your theme's functions.php file or in your custom plugin file. and change according to your need. function rj_wp_trim_excerpt($text) { $raw_excerpt = $text; if ( '' == $text ) {     $text = get_the_content('');     $text = strip_shortcodes( $text );     $text = apply_filters('the_content', $text);     $text = str_replace(']]>', ']]&gt;', $text);          $allowed_tags = '<p>,<a>'; // write your tags here for allow them in excerpt with comma seprated     $text = strip_tags($text, $allowed_tags);          $excerpt_word_count = 55; // change length of excerpt according to your need     $excerpt_length = apply_filters('excerpt_length', $excerpt_word_count);          $excerpt_end = '[...]';     $excerpt_more = apply_filters('excerpt_more', ' ' . $excerpt_end);          $words = preg_split("/[\n\r\t ]+/", $text, $excerpt_length + 1, PREG_SPL

How to add a shortcode button to wordpress page or post editor tinymce

Just copy and paste below code into your theme's functions.php file or your custom plugin's file and change according to your shortcode. add_action( 'init', 'rj_ctn_buttons' ); function rj_ctn_buttons() {     add_filter( "mce_external_plugins", "rj_add_ctn_buttons" );     add_filter( 'mce_buttons', 'rj_register_ctn_buttons' ); } function rj_add_ctn_buttons( $plugin_array ) {     $plugin_array['rj_ctn'] = get_stylesheet_directory_uri() . '/js/rj-ctn-plugin.js';  //include shortcode plugin js file in tinymce plugins     return $plugin_array; } function rj_register_ctn_buttons( $buttons ) {     array_push( $buttons, 'ctn' );  // add button to tinymce buttons     return $buttons; } and my rj-ctn-plugin.js file is as below (function() {     tinymce.create('tinymce.plugins.Rj_ctn', {         init : function(ed, url) {             ed.addButton('ctn', {                 ti

How to change user id on checkout page for assign order to different user in woocommerce wordpress

Just copy and paste below code into your theme's functions.php file or in your custom plugin file function rj_replace_user_id_with_session_id(){     if(!session_id()){         session_start();     }     if(isset($_SESSION['order_replace_by_user_id'])){            return $_SESSION['order_replace_by_user_id']; // return user id you want to assign order     } } add_filter( 'woocommerce_checkout_customer_id', 'rj_replace_user_id_with_session_id' );

How to use wordpress default media uploader at front end for user images upload

For add wordpress default media uploader at your site front end . just copy and paste below code into your theme's functions.php file or in your custom plugins file For use media uploader first need to add media js file so paste below code into your file function rj_wp_enqueue_media() {  if ( ! is_admin()  ) {         wp_enqueue_media(); } } add_action( 'wp_enqueue_scripts', 'rj_wp_enqueue_media' ); // For give permission to user upload images or file you must need to assign capability to user so add below code into file and change user role as per your requirement add_action('init', 'rj_allow_customer_uploads', 20); add_action('admin_init', 'rj_allow_customer_uploads', 20); function rj_allow_customer_uploads() {     global $wpdb;     if ( current_user_can('customer') || current_user_can('subscriber') ) {     $customer = get_role('customer');     $customer->add_cap('upload_files')

How to force use https insted of http for all javascript js file or stylesheet css files in wordpress

Just copy and paste below code into your theme's functions.php file add_action('wp_print_scripts', 'rj_force_ssl_scripts', 100); add_action('wp_print_styles', 'rj_force_ssl_styles', 100); function rj_force_ssl_scripts() {     if (!is_admin()) {         if (!empty($_SERVER['HTTPS'])) // or you can also use is_ssl() function for check ssl         {             global $wp_scripts;             foreach ((array) $wp_scripts->registered as $script) {                 if (stripos($script->src, 'http://', 0) !== FALSE)                     $script->src = str_replace('http://', 'https://', $script->src);             }         }     } } function rj_force_ssl_styles() {     if (!is_admin()) {         if (!empty($_SERVER['HTTPS'])) // or you can also use is_ssl() function for check ssl         {             global $wp_styles;             foreach ((array) $wp_styles->registered as $scri

JQuery html form disable form submit on press enter

Just use below code and replace your id with "rjform" jQuery('#rjform').on('keyup keypress', function(e) {   var code = e.keyCode || e.which;   if (code == 13) {     e.preventDefault();     return false;   } });

How to remove all actions for wp_head or wp_footer for specific template page or as you want

For remove all css and scripts file just copy and paste below code into your functions.php and change according to your need function rj_unhook_wp_head_footer(){     global $wp_filter,$wpdb,$wp_query;     if(is_page('advanced-workshop')) // here i checking for particular page by slug     { foreach ( $wp_filter['wp_head'] as $priority => $wp_head_hooks ) { if( is_array( $wp_head_hooks ) ){ foreach ( $wp_head_hooks as $wp_head_hook ) {                                   remove_action( 'wp_head', $wp_head_hook['function'], $priority ); } } } foreach ($wp_filter['wp_footer'] as $priority => $wp_footer_hooks ) { if( is_array( $wp_footer_hooks ) ){ foreach ( $wp_footer_hooks as $wp_footer_hook ) { remove_action( 'wp_footer', $wp_footer_hook['function'], $priority ); } } }     }   } add_action( 'wp', 'rj_unhook_wp_head_footer' );

How to create or register custom taxonomy like categories or tag for custom post type or default post type wordpress

For create a custom taxonomy for your custom post type just copy and paste below code into your theme's functions.php add_action( 'init', 'rj_create_guide_taxonomy', 0 ); function rj_create_guide_taxonomy() { $labels = array( 'name'              => _x( 'Categories', 'taxonomy general name' ), 'singular_name'     => _x( 'Category', 'taxonomy singular name' ), 'search_items'      => __( 'Search Categories' ), 'all_items'         => __( 'All Categories' ), 'parent_item'       => __( 'Parent Category' ), 'parent_item_colon' => __( 'Parent Category:' ), 'edit_item'         => __( 'Edit Category' ), 'update_item'       => __( 'Update Category' ), 'add_new_item'      => __( 'Add New Category' ), 'new_item_name'     => __( 'New Category

How to add a custom tab for single product tabs in woocommerce wordpress

For add a custom tab in single product page tabs just copy and paste below code into your theme's functions.php file add_filter( 'woocommerce_product_tabs', 'rj_single_product_additional_tab' ); function rj_single_product_additional_tab( $tabs ) { $tabs['additional_info'] = array( 'title' => __( 'Additional Info', 'woocommerce' ), 'priority' => 1, 'callback' => 'rj_single_product_additional_tab_callback' ); return $tabs; } function rj_single_product_additional_tab_callback() { global $post,$product,$wpdb; // your display content here }

How to add a custom column in custom post type list in admin side wordpress

For add a custom column in admin side list for custom post type or any post type just copy and paste below code into your theme's functions.php function rj_display_rank_column_data( $column, $post_id ) {     global $wpdb;     switch ( $column ) {         case 'rank' :                     $rank = get_post_meta($post_id,'optimus_rank_field',true);                if($rank!='9999' && $rank!='')                {                 echo $rank;                }else                {                 echo '-';                }             break;     } } // add_action( 'manage_{custom_post_type}_posts_custom_column' , 'rj_display_rank_column_data', 10, 2 ); orignal hook add_action( 'manage_portfolio_posts_custom_column' , 'rj_display_rank_column_data', 10, 2 ); function rj_add_rank_column( $columns ) {             $columns['rank'] = __( 'Rank', 'enfold' );         return $columns; } //a

How to change wp_nav_menu walker or any other argument by filter in wordpress

For change wp_nav_menu argument for specific menu or all menu or change walker class for menu just copy and paste below code into your theme's functions.php file and change menu slug as per your need add_filter('wp_nav_menu_args','rj_change_walker_for_footer_menus',10,1); function rj_change_walker_for_footer_menus($args) {     global $wpdb;     if($args['menu']!='' && in_array($args['menu']->slug,array('footer-menu1','footer-menu2','footer-menu3')))     {         $args['fallback_cb']           = 'RJFusionFootermenuWalker::fallback';             $args['walker']    =new RJFusionFootermenuWalker();     }     return $args; }

How to change navigation menu display style in wordpress

<?php For change navigation menu display style you need to call your custom walker class. When you can your navgation menu just add walker argument in it and initialize your walker class.. wp_nav_menu(array(                 'theme_location'    => 'main_navigation',                 'depth'                => 5,                 'menu_class'          => 'fusion-menu',                 'items_wrap'         => '<ul id="%1$s" class="%2$s">%3$s</ul>',                 'fallback_cb'           => 'RJFusionFootermenuWalker::fallback',                 'walker'            => new RJFusionFootermenuWalker(),                 'container_class'    => 'fusion-main-menu'             )); Below is one sample for how to create a walker or how to extend walker_nav_menu class // Dont duplicate me! if( ! class_exists( 'RJFusionFootermenuWalker' ) ) {    

How to change cart product price dynamically in woocommerce worpdress

For change cart product price dynamically just copy and paste below code in your theme's functions.php and change code according to your need. add_action( 'woocommerce_get_price', 'rj_bill_payment_price_change_for_customer',10, 2 ); function rj_bill_payment_price_change_for_customer( $price, $product ) {     global $wpdb,$post,$woocommerce;     // do stuff here as per your need     return $price; }

How to change realted product thumbnail size in woocommerce single product page wordpress

For change the related product thumbnail size in single product page woocommerce paste below code in your theme's functions.php file below code is tested and works fine. add_action( 'after_setup_theme', 'rj_remove_loop_thumbnail_filter', 10 ); function rj_remove_loop_thumbnail_filter() {     remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 10 ); } add_filter('woocommerce_related_products_args','rj_related_product_args'); function rj_related_product_args($query_args) {     if( is_singular( 'product' ) ) {    if( ! empty( $query_args ) ) {             set_query_var( 'related_products', true );         }     }     return $query_args; } remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 10 ); add_action( 'woocommerce_before_shop_loop_item_title','rj_change_related_p