Add Icon to Site Link in the WordPress Admin Bar

Each button in the Admin bar has a self-defining and space-saving icon. But the link to the blog frontend (which is represented as a blog title), has no icon. If you want, you can change it quickly – here is a small solution.


Screenshot Admin Bar Icon Example

The following code belongs in the functions.php of the Theme, or better, in a Plugin. It adds the current favicon before the blog title. And to fit the image into the overall picture of the admin bar, we darkened it and and gave it a round shape.


			#wp-admin-bar-site-name > a.ab-item:before {
				float: left;
				width: 16px;
				height: 16px;
				margin: 5px 5px 0 -1px;
				display: block;
				content: "";
				opacity: 0.4;
				background: #000 url("http://www.google.com/s2/u/0/favicons?domain=' . parse_url( home_url(), PHP_URL_HOST ). '");
				border-radius: 16px;
			}
			#wp-admin-bar-site-name:hover > a.ab-item:before {
				opacity: 1;
			}
		';
	}

}

Guest Post

Sergej Müller AvatarThis post is written by Sergej Müller wpseo.de, who created the popular WordPress Plugin to optimize your SEO.

Thank you very much from our part to Sergej.

If you also like to have your interesting post published on our website, please let us know on our contact page. Of course we will appreciate your contribution!


Posted

in

by

Comments

3 responses to “Add Icon to Site Link in the WordPress Admin Bar”

  1. […] WP-Engineer zeigt uns Sergej Müller, wie man in die WordPress-Adminbar ein Icon für den Link zur eigenen Website […]

  2. Casey Avatar

    This is pretty cool, but I’d also like to see how to replace the WordPress logo with the site Favicon. That would be really useful.