<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Aman Mehra</title>
    <description>The latest articles on DEV Community by Aman Mehra (@amanmehra).</description>
    <link>https://dev.to/amanmehra</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F677012%2F189f0663-9652-44c2-b7c5-512269ef6035.png</url>
      <title>DEV Community: Aman Mehra</title>
      <link>https://dev.to/amanmehra</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/amanmehra"/>
    <language>en</language>
    <item>
      <title>How to Hide Admin Bar in WordPress?</title>
      <dc:creator>Aman Mehra</dc:creator>
      <pubDate>Tue, 10 Aug 2021 08:18:47 +0000</pubDate>
      <link>https://dev.to/amanmehra/how-to-hide-admin-bar-in-wordpress-lhm</link>
      <guid>https://dev.to/amanmehra/how-to-hide-admin-bar-in-wordpress-lhm</guid>
      <description>&lt;p&gt;There are many ways to &lt;a href="https://yourblogcoach.com/how-to-hide-admin-bar-in-wordpress/"&gt;hide the admin bar&lt;/a&gt; and many reasons you may want to hide the admin bar. You can do this by adding some code in your theme’s &lt;strong&gt;functions.php file&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Disable the WordPress Admin Bar for All Users&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;add_filter(‘show_admin_bar’, ‘__return_false’);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Disable the WordPress Admin Bar for Specific User Roles&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function hide_admin_bar( $show ) {
    if ( current_user_can( 'subscriber' ) || current_user_can( 'author' ) ) :
        return false;
    endif;

    return $show;
}
add_filter( 'show_admin_bar', 'hide_admin_bar' );
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Disable the WordPress Admin Bar for All Users Except Administrators&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function hide_admin_bar( $show ) {

    if ( ! current_user_can( 'administrator' ) ) :
        return false;
    endif;

    return $show;

}
add_filter( 'show_admin_bar', 'hide_admin_bar' );
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can hide admin bar on any condition based. More wordpress tutorial on &lt;a href="https://yourblogcoach.com/"&gt;www.yourblogcoach.com&lt;/a&gt;&lt;/p&gt;

</description>
      <category>wordpress</category>
      <category>php</category>
      <category>action</category>
      <category>hooks</category>
    </item>
    <item>
      <title>Custom WooCommerce Product View Counter</title>
      <dc:creator>Aman Mehra</dc:creator>
      <pubDate>Sat, 07 Aug 2021 08:27:45 +0000</pubDate>
      <link>https://dev.to/amanmehra/custom-woocommerce-product-view-counter-30mm</link>
      <guid>https://dev.to/amanmehra/custom-woocommerce-product-view-counter-30mm</guid>
      <description>&lt;p&gt;The product view counter is a count of the total page view of that specific product page. This means when someone visits your product page then this counter will auto-increment each time. It will increment one by one and show you the total views of that page.&lt;/p&gt;

&lt;p&gt;Why you should add it? Because it is a very powerful impression for visitors and when they look this product has that many views then it will think about to go with this product and have it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://yourblogcoach.com/custom-woocommerce-product-view-counter/"&gt;Custom WooCommerce Product View Counter&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To make a custom product view counter in woocommerce, we will make a hook function to add a post meta field in the wp_postmeta table.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Functions reference:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;To get the post meta field based on product ID &lt;strong&gt;get_post_meta()&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;To update the post meta field &lt;strong&gt;update_post_meta()&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;To show counter on product page &lt;strong&gt;woocommerce_before_add_to_cart_button&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;To show counter on shop page or archove page &lt;strong&gt;woocommerce_after_shop_loop_item&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;add_action('wp', 'product_view_counter'); 
function product_view_counter() { 

         global $post; 
         if ( is_product() ){ 
             $meta = get_post_meta( $post-&amp;gt;ID, '_total_views_count', TRUE ); 
             $meta = ($meta) ? $meta + 1 : 1;  
             update_post_meta( $post-&amp;gt;ID, '_total_views_count', $meta ); 
         } 

} 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add the above code in your active theme’s functions.php file, I’ll recommend using a &lt;a href="https://yourblogcoach.com/how-to-create-a-child-theme-in-wordpress/"&gt;child theme&lt;/a&gt; for any functionality.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Show them on the product page.&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;add_action( 'woocommerce_before_add_to_cart_button', 'show_product_view_counter_on_product_page', 10); 
    function show_product_view_counter_on_product_page() { 

        global $product; 
        $id = $product-&amp;gt;id;          
        $meta = get_post_meta( $id, '_total_views_count', true); 
        if(!$meta) { 
            $count = 0; 
        } else {         
            $count = $meta;  
        }        
        echo "&amp;lt;div class="custom-visitor-count"&amp;gt;&amp;lt;i class="fa fa-eye"&amp;gt;&amp;lt;/i&amp;gt;&amp;lt;span class="counter-value"&amp;gt;".$count." Views&amp;lt;/span&amp;gt;&amp;lt;/div&amp;gt;"; 

} 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also show the counter on product archive page/shop page with this action hook &lt;strong&gt;woocommerce_after_shop_loop_item&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;And also make a conditions in the code for &lt;a href="https://yourblogcoach.com/custom-woocommerce-product-view-counter/"&gt;product view counter&lt;/a&gt; based on IP address.&lt;/p&gt;

</description>
      <category>wordpress</category>
      <category>woocommerce</category>
      <category>productviewcounter</category>
      <category>customization</category>
    </item>
    <item>
      <title>How to Disable Widget Block Editor in WordPress?</title>
      <dc:creator>Aman Mehra</dc:creator>
      <pubDate>Fri, 06 Aug 2021 11:04:44 +0000</pubDate>
      <link>https://dev.to/amanmehra/how-to-disable-widget-block-editor-in-wordpress-4dm1</link>
      <guid>https://dev.to/amanmehra/how-to-disable-widget-block-editor-in-wordpress-4dm1</guid>
      <description>&lt;p&gt;In the latest version of &lt;a href="https://wordpress.org/download/?u=t&amp;amp;m=o#download-install"&gt;WordPress 5.8&lt;/a&gt; comes with some new features and one of them is Widget Block Editor. Widget block editor has based on the Gutenberg editor that you have in post add/edit.&lt;/p&gt;

&lt;p&gt;So here, we will see how to disable the widget block editor in WordPress and get back to the classic editor.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Using the use_widgets_block_editor&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Just add the following one-line code in your active theme’s functions.php file and save it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;add_filter( 'use_widgets_block_editor', '__return_false' );
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Using the rempove_theme_support&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The function remove_theme_support(‘widget-block-editor’) will disable the block editor. See the code below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function disable_wbe_theme_support() {
    remove_theme_support( 'widgets-block-editor' );
}
add_action( 'after_setup_theme', 'disable_wbe_theme_support' );
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Using the Plugins&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You can also use the plugin to disable the block widget editor and get back your classic widget area.&lt;/p&gt;

&lt;p&gt;You need to just install the plugins and activate it and follow the settings if they have one.&lt;/p&gt;

&lt;p&gt;The are the two plugin to disable the widget block editor.&lt;/p&gt;

&lt;ul&gt;
    &lt;li&gt;&lt;a href="https://wordpress.org/plugins/classic-widgets/"&gt;Classic Widgets&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="https://wordpress.org/plugins/disable-gutenberg/"&gt;Disable Gutenberg&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can see full tutorial on &lt;a href="https://yourblogcoach.com/how-to-disable-widget-block-editor-gutenberg-in-wordpress/?u=t&amp;amp;m=o"&gt;disable widget block editor&lt;/a&gt; and how to install plugins.&lt;/p&gt;

</description>
      <category>wordpress</category>
      <category>widget</category>
      <category>plugin</category>
      <category>disablewidgetblockeditor</category>
    </item>
  </channel>
</rss>
