<?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: Roman Grigorian</title>
    <description>The latest articles on DEV Community by Roman Grigorian (@roman-grigorian).</description>
    <link>https://dev.to/roman-grigorian</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%2F2736803%2F9e7bb5fa-18f8-4b77-b1ed-7ce5f1992b56.png</url>
      <title>DEV Community: Roman Grigorian</title>
      <link>https://dev.to/roman-grigorian</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/roman-grigorian"/>
    <language>en</language>
    <item>
      <title>How to Hide WordPress Admin Bar</title>
      <dc:creator>Roman Grigorian</dc:creator>
      <pubDate>Tue, 21 Jan 2025 10:44:39 +0000</pubDate>
      <link>https://dev.to/roman-grigorian/how-to-hide-wordpress-admin-bar-273</link>
      <guid>https://dev.to/roman-grigorian/how-to-hide-wordpress-admin-bar-273</guid>
      <description>&lt;p&gt;Admin Bar for logged-in users in WordPress is a convenient solution for quick access to often-used things like editing a post or purging website cache. Though, there is one thing I always hated about it, especially when developing a new website. The admin bar draws too much attention and makes it harder to focus on the design and content. Of course, there is an option to hide it completely, but every now and then, I need quick access to some of the basic stuff, like switching to page editing.&lt;/p&gt;

&lt;p&gt;If you want to completely disable the admin bar, here’s a screenshot of where it can be toggled:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8cquqthe6tih26u9e7vk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8cquqthe6tih26u9e7vk.png" alt="Image description" width="800" height="532"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I’m not a fan of this solution, as I do like how easy it is to switch back and forth, but at the same time, I wanted something more elegant. A couple of years ago, I came across this &lt;a href="https://wp-kama.ru/id_6339/10-hakov-dlya-admin-bara-wordpress.html" rel="noopener noreferrer"&gt;tweak&lt;/a&gt;. So I took it further and packed it into a plugin with some adjustments. Just compare the original admin bar and mine:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fasww4xlgawsh7z1u1yqn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fasww4xlgawsh7z1u1yqn.png" alt="Image description" width="650" height="330"&gt;&lt;/a&gt;&lt;br&gt;
Default admin bar is visible all the time&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe2pfy5fvc4es8mmaiqko.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe2pfy5fvc4es8mmaiqko.png" alt="Image description" width="650" height="330"&gt;&lt;/a&gt;&lt;br&gt;
Tweaked admin bar is hidden under the red circle&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft0s7vxi8tm7hv4prn16j.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft0s7vxi8tm7hv4prn16j.png" alt="Image description" width="650" height="330"&gt;&lt;/a&gt;&lt;br&gt;
Once the circle is hovered the vertical admin bar appears&lt;/p&gt;

&lt;p&gt;As you can see, there is no black bar. Instead, you get a small red circle (the color and the icon can be changed). Once the icon gets hovered, the &lt;strong&gt;vertical&lt;/strong&gt; bar becomes revealed. So all of the basic links stay accessible but hidden until you need them. Neat.&lt;/p&gt;

&lt;p&gt;My solution isn’t ideal. Probably the most significant drawback is that it might not work properly with long menu titles from various plugins. It doesn’t bother me since I keep my plugin stack lean. For instance, this website is using like 7 of them.&lt;/p&gt;

&lt;p&gt;Besides repositioning the admin bar, my solution changes the site title to the URL address. It is handy when working with a website with a long title. Domains are usually shorter.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to install it
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Option 1&lt;/strong&gt; is to use the single-file plugin, which should be uploaded to the /wp-content/plugins folder and activated in the Plugins section. You can download the plugin for my original article at: &lt;a href="https://romangr.com/blog/wp-admin-bar" rel="noopener noreferrer"&gt;https://romangr.com/blog/wp-admin-bar&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Option 2&lt;/strong&gt; is to put the code to the functions.php file of your theme:&lt;br&gt;
`// display domain in the admin bar instead of site title&lt;br&gt;
add_action( 'admin_bar_menu', 'customize_my_wp_admin_bar', 80 );&lt;br&gt;
function customize_my_wp_admin_bar( $wp_admin_bar ) {&lt;br&gt;
    $node = $wp_admin_bar-&amp;gt;get_node('site-name');&lt;br&gt;
    $new_site_name = preg_replace("(^https?://)", "", get_home_url() );&lt;br&gt;
    $node-&amp;gt;title = $new_site_name;&lt;br&gt;
    $wp_admin_bar-&amp;gt;add_node($node);&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;final class Kama_Collapse_Toolbar {&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public static function init(){
    add_action( 'admin_bar_init', [ __CLASS__, 'hooks' ] );
}

public static function hooks(){

    // remove html margin bumps
    remove_action( 'wp_head', '_admin_bar_bump_cb' );

    add_action( 'wp_head', [ __CLASS__, 'collapse_styles' ] );
}

public static function collapse_styles(){

    // do nothing for admin-panel.
    // Remove this if you want to collapse admin-bar in admin-panel too.
    if( is_admin() ){
        return;
    }

    ob_start();
    ?&amp;gt;
    &amp;lt;style id="kama_collapse_admin_bar"&amp;gt;
        #wpadminbar .quicklinks&amp;gt;ul&amp;gt;li&amp;gt;a { padding: 0 8px 0 5px; }
        #wpadminbar #wp-admin-bar-site-name&amp;gt;.ab-item:before { color: red; }

        #wpadminbar.nojq .quicklinks .ab-top-menu&amp;gt;li&amp;gt;.ab-item:focus,
        #wpadminbar:not(.mobile) .ab-top-menu&amp;gt;li&amp;gt;.ab-item:focus,
        #wpadminbar .ab-top-menu&amp;gt;li.hover&amp;gt;.ab-item {
            background: none;
        }
        #wpadminbar #wp-admin-bar-site-name&amp;gt;.ab-item:before {
            content: "\f159";
        }
        #wp-admin-bar-search,
        #wp-admin-bar-comments,
        #wp-admin-bar-updates {
            display: none !important;
        }
        #wpadminbar ul:not(.ab-submenu)&amp;gt;li&amp;gt;a.ab-item {
            white-space: nowrap;
            overflow: hidden;
        }
        #wpadminbar ul:not(.ab-submenu)&amp;gt;li&amp;gt;a.ab-item:after {
            content: '';
            display: block;
            pointer-events: none;
            top: 0;
            right: 0;
            bottom: 0;
            background-image: -webkit-gradient(linear,left top,right top,from(rgba(29,35,39,0)),color-stop(95%,#1d2327),to(#1d2327));
            background-image: linear-gradient(left,rgba(29,35,39,0) 0,#1d2327 95%,#1d2327 100%);
            background-image: -webkit-linear-gradient(left,rgba(29,35,39,0) 0,#1d2327 95%,#1d2327 100%);
            background-image: -ms-linear-gradient(left,rgba(29,35,39,0) 0,#1d2327 95%,#1d2327 100%);
            width: 50px;
            position: absolute;
        }
        #wpadminbar .ab-icon, #wpadminbar .ab-item:before, #wpadminbar&amp;gt;#wp-toolbar&amp;gt;#wp-admin-bar-root-default .ab-icon, .wp-admin-bar-arrow {
            margin-right: 8px;
        }


        #wpadminbar{ background:none; float:left; width:auto; height:auto; bottom:0; min-width:0 !important; }
        #wpadminbar &amp;gt; *{ float:left !important; clear:both !important; }
        #wpadminbar .ab-top-menu li{ float:none !important; }
        #wpadminbar .ab-top-secondary{ float: none !important; }
        #wpadminbar .ab-top-menu&amp;gt;.menupop&amp;gt;.ab-sub-wrapper{ top:0; left:100%; white-space:nowrap; }
        #wpadminbar .quicklinks&amp;gt;ul&amp;gt;li&amp;gt;a{ padding-right:17px; }
        #wpadminbar .ab-top-secondary .menupop .ab-sub-wrapper{ left:100%; right:auto; }
        html{ margin-top:0!important; }

        #wpadminbar{ overflow:hidden; width:33px; height:30px; }
        #wpadminbar:hover{ overflow:visible; width:auto; height:auto; background:rgba(102,102,102,.7); }

        /* the color of the main icon */
        #wp-admin-bar-&amp;lt;?= is_multisite() ? 'my-sites' : 'site-name' ?&amp;gt; .ab-item:before{ color:#797c7d; }

        /* hide wp-logo */
        #wp-admin-bar-wp-logo{ display:none; }
        /* #wp-admin-bar-search{ display:none; } */

        /* edit for twentysixteen */
        body.admin-bar:before{ display:none; }

        /* for almin panel --- */
        @media screen and ( min-width: 782px ) {
            html.wp-toolbar{ padding-top:0 !important; }
            #wpadminbar:hover{ background:#1d2327; width: 160px }
            #wpadminbar .quicklinks&amp;gt;ul&amp;gt;li&amp;gt;a { width: 138px }
            #adminmenu{ margin-top:48px !important; }
        }

        /* Gutenberg */
        #wpwrap .edit-post-header{ top:0; }
        #wpwrap .edit-post-sidebar{ top:56px; }
    &amp;lt;/style&amp;gt;
    &amp;lt;?php
    $styles = ob_get_clean();

    echo preg_replace( '/[\n\t]/', '', $styles ) ."\n";
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}&lt;/p&gt;

&lt;p&gt;Kama_Collapse_Toolbar::init();`&lt;/p&gt;

&lt;p&gt;Since I reuse it on a handful of websites, I find it more convenient to go with the first option. And it keeps my functions.php file leaner, which is a benefit for me.&lt;/p&gt;

&lt;h2&gt;
  
  
  A couple of things to note
&lt;/h2&gt;

&lt;h3&gt;
  
  
  How to change the icon
&lt;/h3&gt;

&lt;p&gt;To change the icon, you should change the &lt;code&gt;wpadminbar #wp-admin-bar-site-name&amp;gt;.ab-item:before&lt;/code&gt; element. Pick any icon from the &lt;a href="https://developer.wordpress.org/resource/dashicons/" rel="noopener noreferrer"&gt;dashicons&lt;/a&gt; and edit the content property in CSS.&lt;/p&gt;

&lt;h3&gt;
  
  
  How to change the icon color
&lt;/h3&gt;

&lt;p&gt;Once again, go to the code and find edit the color for the &lt;code&gt;wpadminbar #wp-admin-bar-site-name&amp;gt;.ab-item:before&lt;/code&gt; element. For me, the red color works well due to the contrast.&lt;/p&gt;

&lt;h3&gt;
  
  
  How to preserve the site title in the admin bar
&lt;/h3&gt;

&lt;p&gt;Remove this code from either the plugin file or your functions.php file:&lt;br&gt;
&lt;code&gt;add_action( 'admin_bar_menu', 'customize_my_wp_admin_bar', 80 );&lt;br&gt;
function customize_my_wp_admin_bar( $wp_admin_bar ) {&lt;br&gt;
    $node = $wp_admin_bar-&amp;gt;get_node('site-name');&lt;br&gt;
    $new_site_name = preg_replace("(^https?://)", "", get_home_url() );&lt;br&gt;
    $node-&amp;gt;title = $new_site_name;&lt;br&gt;
    $wp_admin_bar-&amp;gt;add_node($node);&lt;br&gt;
}&lt;/code&gt;&lt;/p&gt;

</description>
      <category>wordpress</category>
      <category>css</category>
    </item>
  </channel>
</rss>
