{"id":17,"date":"2019-11-06T21:39:17","date_gmt":"2019-11-07T03:39:17","guid":{"rendered":"https:\/\/travisolson.net\/code\/?p=17"},"modified":"2019-11-07T10:52:34","modified_gmt":"2019-11-07T16:52:34","slug":"wordpress-hide-admin-bar-for-users-that-are-not-admins","status":"publish","type":"post","link":"https:\/\/www.travisolson.net\/code\/wordpress-hide-admin-bar-for-users-that-are-not-admins\/","title":{"rendered":"WordPress: Hide Admin Bar For Users That Are Not Admins"},"content":{"rendered":"<p>There are numerous plugins that offer this functionality. For example, the User Role Editor plugin has an option to hide the admin bar for each user role. If, however, you want a quick solution to implement this in your code without the need for installing a plugin, here&#8217;s how you can do that.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"php\">\/* Hide admin bar for everyone except admins *\/\r\nfunction myprefix_remove_admin_bar() {\r\n  if (!current_user_can('administrator') !is_admin()) {\r\n    show_admin_bar(false);\r\n  }\r\n}\r\nadd_action('after_setup_theme', 'myprefix_remove_admin_bar');<\/pre>\n<p>This snippet only applies to non-admin pages.\u00a0 If a user has access to the back-end it will still show the admin bar on those pages.\u00a0 The <code class=\"EnlighterJSRAW\" data-enlighter-language=\"php\">is_admin()<\/code> function is used to determine if the current page is an admin page or not.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>There are numerous plugins that offer this functionality. For example, the User Role Editor plugin has an option to hide the admin bar for each user role. If, however, you want a quick solution to implement this in your code without the need for installing a plugin, here&#8217;s how you can do that. \/* Hide&#8230;  <a class=\"excerpt-read-more\" href=\"https:\/\/www.travisolson.net\/code\/wordpress-hide-admin-bar-for-users-that-are-not-admins\/\" title=\"Read WordPress: Hide Admin Bar For Users That Are Not Admins\">Read more &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-17","post","type-post","status-publish","format-standard","hentry","category-wordpress"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>WordPress: Hide Admin Bar For Users That Are Not Admins - Travis Olson&#039;s Code Snippets<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.travisolson.net\/code\/wordpress-hide-admin-bar-for-users-that-are-not-admins\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"WordPress: Hide Admin Bar For Users That Are Not Admins - Travis Olson&#039;s Code Snippets\" \/>\n<meta property=\"og:description\" content=\"There are numerous plugins that offer this functionality. For example, the User Role Editor plugin has an option to hide the admin bar for each user role. If, however, you want a quick solution to implement this in your code without the need for installing a plugin, here&#8217;s how you can do that. \/* Hide... Read more &raquo;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.travisolson.net\/code\/wordpress-hide-admin-bar-for-users-that-are-not-admins\/\" \/>\n<meta property=\"og:site_name\" content=\"Travis Olson&#039;s Code Snippets\" \/>\n<meta property=\"article:published_time\" content=\"2019-11-07T03:39:17+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-11-07T16:52:34+00:00\" \/>\n<meta name=\"author\" content=\"Travis Olson\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Travis Olson\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.travisolson.net\/code\/wordpress-hide-admin-bar-for-users-that-are-not-admins\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.travisolson.net\/code\/wordpress-hide-admin-bar-for-users-that-are-not-admins\/\"},\"author\":{\"name\":\"Travis Olson\",\"@id\":\"https:\/\/www.travisolson.net\/code\/#\/schema\/person\/0170ab5b2e7a3d88436375cc50336934\"},\"headline\":\"WordPress: Hide Admin Bar For Users That Are Not Admins\",\"datePublished\":\"2019-11-07T03:39:17+00:00\",\"dateModified\":\"2019-11-07T16:52:34+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.travisolson.net\/code\/wordpress-hide-admin-bar-for-users-that-are-not-admins\/\"},\"wordCount\":105,\"publisher\":{\"@id\":\"https:\/\/www.travisolson.net\/code\/#\/schema\/person\/0170ab5b2e7a3d88436375cc50336934\"},\"articleSection\":[\"WordPress\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.travisolson.net\/code\/wordpress-hide-admin-bar-for-users-that-are-not-admins\/\",\"url\":\"https:\/\/www.travisolson.net\/code\/wordpress-hide-admin-bar-for-users-that-are-not-admins\/\",\"name\":\"WordPress: Hide Admin Bar For Users That Are Not Admins - Travis Olson&#039;s Code Snippets\",\"isPartOf\":{\"@id\":\"https:\/\/www.travisolson.net\/code\/#website\"},\"datePublished\":\"2019-11-07T03:39:17+00:00\",\"dateModified\":\"2019-11-07T16:52:34+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.travisolson.net\/code\/wordpress-hide-admin-bar-for-users-that-are-not-admins\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.travisolson.net\/code\/wordpress-hide-admin-bar-for-users-that-are-not-admins\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.travisolson.net\/code\/wordpress-hide-admin-bar-for-users-that-are-not-admins\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.travisolson.net\/code\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"WordPress: Hide Admin Bar For Users That Are Not Admins\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.travisolson.net\/code\/#website\",\"url\":\"https:\/\/www.travisolson.net\/code\/\",\"name\":\"Travis Olson&#039;s Code Snippets\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/www.travisolson.net\/code\/#\/schema\/person\/0170ab5b2e7a3d88436375cc50336934\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.travisolson.net\/code\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/www.travisolson.net\/code\/#\/schema\/person\/0170ab5b2e7a3d88436375cc50336934\",\"name\":\"Travis Olson\",\"logo\":{\"@id\":\"https:\/\/www.travisolson.net\/code\/#\/schema\/person\/image\/\"},\"url\":\"https:\/\/www.travisolson.net\/code\/author\/travis-olson\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"WordPress: Hide Admin Bar For Users That Are Not Admins - Travis Olson&#039;s Code Snippets","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.travisolson.net\/code\/wordpress-hide-admin-bar-for-users-that-are-not-admins\/","og_locale":"en_US","og_type":"article","og_title":"WordPress: Hide Admin Bar For Users That Are Not Admins - Travis Olson&#039;s Code Snippets","og_description":"There are numerous plugins that offer this functionality. For example, the User Role Editor plugin has an option to hide the admin bar for each user role. If, however, you want a quick solution to implement this in your code without the need for installing a plugin, here&#8217;s how you can do that. \/* Hide... Read more &raquo;","og_url":"https:\/\/www.travisolson.net\/code\/wordpress-hide-admin-bar-for-users-that-are-not-admins\/","og_site_name":"Travis Olson&#039;s Code Snippets","article_published_time":"2019-11-07T03:39:17+00:00","article_modified_time":"2019-11-07T16:52:34+00:00","author":"Travis Olson","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Travis Olson","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.travisolson.net\/code\/wordpress-hide-admin-bar-for-users-that-are-not-admins\/#article","isPartOf":{"@id":"https:\/\/www.travisolson.net\/code\/wordpress-hide-admin-bar-for-users-that-are-not-admins\/"},"author":{"name":"Travis Olson","@id":"https:\/\/www.travisolson.net\/code\/#\/schema\/person\/0170ab5b2e7a3d88436375cc50336934"},"headline":"WordPress: Hide Admin Bar For Users That Are Not Admins","datePublished":"2019-11-07T03:39:17+00:00","dateModified":"2019-11-07T16:52:34+00:00","mainEntityOfPage":{"@id":"https:\/\/www.travisolson.net\/code\/wordpress-hide-admin-bar-for-users-that-are-not-admins\/"},"wordCount":105,"publisher":{"@id":"https:\/\/www.travisolson.net\/code\/#\/schema\/person\/0170ab5b2e7a3d88436375cc50336934"},"articleSection":["WordPress"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.travisolson.net\/code\/wordpress-hide-admin-bar-for-users-that-are-not-admins\/","url":"https:\/\/www.travisolson.net\/code\/wordpress-hide-admin-bar-for-users-that-are-not-admins\/","name":"WordPress: Hide Admin Bar For Users That Are Not Admins - Travis Olson&#039;s Code Snippets","isPartOf":{"@id":"https:\/\/www.travisolson.net\/code\/#website"},"datePublished":"2019-11-07T03:39:17+00:00","dateModified":"2019-11-07T16:52:34+00:00","breadcrumb":{"@id":"https:\/\/www.travisolson.net\/code\/wordpress-hide-admin-bar-for-users-that-are-not-admins\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.travisolson.net\/code\/wordpress-hide-admin-bar-for-users-that-are-not-admins\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.travisolson.net\/code\/wordpress-hide-admin-bar-for-users-that-are-not-admins\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.travisolson.net\/code\/"},{"@type":"ListItem","position":2,"name":"WordPress: Hide Admin Bar For Users That Are Not Admins"}]},{"@type":"WebSite","@id":"https:\/\/www.travisolson.net\/code\/#website","url":"https:\/\/www.travisolson.net\/code\/","name":"Travis Olson&#039;s Code Snippets","description":"","publisher":{"@id":"https:\/\/www.travisolson.net\/code\/#\/schema\/person\/0170ab5b2e7a3d88436375cc50336934"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.travisolson.net\/code\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/www.travisolson.net\/code\/#\/schema\/person\/0170ab5b2e7a3d88436375cc50336934","name":"Travis Olson","logo":{"@id":"https:\/\/www.travisolson.net\/code\/#\/schema\/person\/image\/"},"url":"https:\/\/www.travisolson.net\/code\/author\/travis-olson\/"}]}},"_links":{"self":[{"href":"https:\/\/www.travisolson.net\/code\/wp-json\/wp\/v2\/posts\/17","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.travisolson.net\/code\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.travisolson.net\/code\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.travisolson.net\/code\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.travisolson.net\/code\/wp-json\/wp\/v2\/comments?post=17"}],"version-history":[{"count":2,"href":"https:\/\/www.travisolson.net\/code\/wp-json\/wp\/v2\/posts\/17\/revisions"}],"predecessor-version":[{"id":27,"href":"https:\/\/www.travisolson.net\/code\/wp-json\/wp\/v2\/posts\/17\/revisions\/27"}],"wp:attachment":[{"href":"https:\/\/www.travisolson.net\/code\/wp-json\/wp\/v2\/media?parent=17"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.travisolson.net\/code\/wp-json\/wp\/v2\/categories?post=17"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.travisolson.net\/code\/wp-json\/wp\/v2\/tags?post=17"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}