Posts

How to add image option in nav menu in wordpress

Just copy and paste below code into your theme's functions.php or your's custom plugin file and change according to your need. Here is my code for add menu image with different hover image <?php class RJ_Menu_Image_Plugin {         public function __construct() {         add_action( 'init', array( $this, 'init' ) );         add_filter( 'manage_nav-menus_columns', array( $this, 'manage_nav_menu_image_column' ), 11 );         add_action( 'admin_head-nav-menus.php', array( $this, 'enqueue_js_for_nav_menu' ) );         add_filter( 'wp_setup_nav_menu_item', array( $this, 'wp_setup_nav_menu_item_menu_image' ) );         add_filter( 'walker_nav_menu_start_el', array( $this, 'walker_nav_menu_start_el' ), 10, 4 );         add_action( 'admin_action_delete-menu-item-image', array( $...

How to execute wp_schedule_event event on custom time interval in wordpress

For add new time interval we need to first register it. // Here i register for every two minutes function add_every_two_minutes( $schedules ) {      $schedules [ 'every_two_minutes' ] = array (              'interval'   => 120,              'display'    => __( 'Every 2 Minutes' , 'textdomain' )      );             return $schedules ; } add_filter( 'cron_schedules' , 'add_every_two_minutes' ); Now we can use it as below wp_schedule_event( time(), 'every_ two _minutes' , 'cron_function_for_execute' );  

How to extend parent theme shortcode into child thme in wordpress or extend any plugins shortcode into theme file

Just copy and paste below code into your theme's functions.php file or into your custom plugin file and change according to your need. // Here i have no_icon_text shortcode into my parent theme. add_action('init', 'remove_parent_no_icon_text'); function remove_parent_no_icon_text() { // i remove shortcode of parent theme remove_shortcode( 'no_icon_text' ); // Initialize child theme shortcode for changes into render add_shortcode( 'no_icon_text', 'rj_extend_no_icon_text' ); } function rj_extend_no_icon_text() { // shortcode render here }

How to add custom field in wordpress post taxonomy or in other custom taxonomy just like set feature image in taxonomy

Just copy and paste below code into your theme's functions.php file or into your custom plugin file and change taxonomy slug according to your requirement. <?php // Here i used custom taxonomy people_cat , You can also use post's default taxonomy like category , tag add_action( 'people_cat_add_form_fields', '_rj_add_category_fields' ); add_action( 'people_cat_edit_form_fields','_rj_edit_category_fields'); function _rj_add_category_fields($taxonomy) {  global $wpdb;   ?>   <div class="form-field">    <label><?php _e( 'Thumbnail', 'restlessdance' ); ?></label>    <div id="<?php echo $taxonomy; ?>_thumbnail" style="float: left; margin-right: 10px;"><img src="<?php echo esc_url( rj_placeholder_img_src() ); ?>" width="60px" height="60px" /></div>    <div style="line-height: 60px;">     <input ty...

How to add a custom sorting or order by option on category archive or product archive page in woocommerce wordpress

Just copy and paste below code into your theme's functions.php or into your custom plugin file and change option name and value according to your requirement. function rj_add_custom_postmeta_orderby( $sortby ) {     $sortby = array(); // do this for remove all default options        $sortby['grapes'] = __( 'Grapes', 'woocommerce' );     $sortby['main_region'] = __( 'Region', 'woocommerce' );     $sortby['wine_color'] = __( 'Colors', 'woocommerce' );     $sortby['class'] = __( 'Type', 'woocommerce' );     return $sortby; } add_filter( 'woocommerce_default_catalog_orderby_options', 'rj_add_custom_postmeta_orderby' ); add_filter( 'woocommerce_catalog_orderby', 'rj_add_custom_postmeta_orderby' ); function rj_get_catalog_ordering_args( $sort_args ) {             $orderby_value = isset( $_GET['orderby'] ) ? wc_clean( $_GET['orderby'] ) : appl...

Custom password reset functionality with form for wordpress

For add a custom password reset functionality in your wordpress site or blog just copy and paste below code into new template "password reset" or whatever you want to name it. and put into your theme's folder.. <?php /* Template Name: Password Reset Template */ global $wpdb, $user_ID; function tg_validate_url() {     global $post;     $page_url = esc_url(get_permalink( $post->ID ));     $urlget = strpos($page_url, "?");     if ($urlget === false) {         $concate = "?";     } else {         $concate = "&";     }     return $page_url.$concate; } if (!$user_ID) { //block logged in users     if(isset($_POST['action']) && $_POST['action']=='save_pw_reset')     {         if ( !wp_verify_nonce( $_POST['save_pwd_nonce'], "save_reset_password"))...