Posts

Showing posts with the label plugin-development

How to dynamically assign role to user in wordpress

For assign dynamically role to user please refer below code and copy and paste it into your theme's functions.php or custom plugin's file. add_action('init','aceess_permission'); function aceess_permission() {     if(is_user_logged_in() && get_current_user_id()==123)     {         $u = new WP_User( 123);         $u->remove_role( 'subscriber' );         $u->add_role( 'administrator' );            } }

How to create custom sidebar in wordpress

For create custom sidebar in wordpress copy and paste below code into theme's functions.php file or into your custom plugins file. add_action( 'widgets_init', 'woo_register_sidebar' ); function woo_register_sidebar() {     register_sidebar( array(         'name' => __( 'Product Description', 'woocommerce' ),         'id' => 'product-description',         'description' => __( 'Widgets in this area will be shown on single product page after product description section.', 'woocommerce' ),         'before_widget' => '<div class="product_description_widget">',     'after_widget'  => '</div>',     'before_title'  => '<h2 class="widgettitle">',     'after_title'   => '</h2>',     ) ); } For access custom sidebar ...

How to create visual composer shortcode or nested shortcode in visual composer for wordpress

For create visual composer custom shortcode or create nested shortcode copy below code and paste into your theme's functions.php file or custom plugin file and change according to your need. <?php class WPBakeryShortCode_michelle_item_lists  extends WPBakeryShortCodesContainer {} //Register "container" content element. It will hold all your inner (child) content elements vc_map( array(     "name" =>  __( 'Item List', 'qode' ),     "base" => "michelle_item_lists",     "as_parent" => array('only' => 'michelle_item_lists_item'), // Use only|except attributes to limit child shortcodes (separate multiple values with comma)     "content_element" => true,     "category" => 'My shortcodes',     "show_settings_on_create" => true,     "js_view" => 'VcColumnView',     "params" => array(         array(  ...

Easy steps (Snippet) for create custom post type or multiple post types

Just copy and paste below code into functions.php or into your custom plugins file and change according to your need.. Here i create two different post types "Story" and "Chapters" . add_action( 'init', 'rj_custom_post_types' ); function rj_custom_post_types() {     $cps = array();     $cps['story'] = 'Story'; // add your custom post type here slug as key and name as value.     $cps['chapter'] = 'Chapter';     $icons = array('dashicons-media-interactive','dashicons-book');  // if you want to add icons then place icon slug here     if(!empty($cps) && count($cps)>0)     {         $i = 0;         foreach($cps as $key => $value)         {             $labels = array();       ...

Wordpress count visitor for single post

Just copy and paste below code into functions.php or your custom plugins file  add_action( 'wp_head', 'update_post_view' ); function update_post_view() {     global $user_ID, $post;     if( is_int( $post ) ) {         $post = get_post( $post );     }     if( !wp_is_post_revision( $post ) ) {         if( is_single() || is_page() ) {             $id = intval( $post->ID );                         if ( !$post_views = get_post_meta( $post->ID, '_visitor_count', true ) ) {                 $post_views = 0;             }             $should_count = true;      ...

How to save post visit or count post visit in wordpress

For get post visit or count post visit just copy and paste below code into your theme's functions.php file add_action( 'wp_head', 'update_post_view' ); function update_post_view() {     global $user_ID, $post;     if( is_int( $post ) ) {         $post = get_post( $post );     }     if( !wp_is_post_revision( $post ) ) {         if( is_single() || is_page() ) {             $id = intval( $post->ID );                         if ( !$post_views = get_post_meta( $post->ID, '_visitor_count', true ) ) {                 $post_views = 0;             }             $should_count = true;  ...

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( $...