Posts

Showing posts from July, 2015

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 }