<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>WP Engineer &#187; Menu Icon</title>
	<atom:link href="http://wpengineer.com/tag/menu-icon/feed/" rel="self" type="application/rss+xml" />
	<link>http://wpengineer.com</link>
	<description>WordPress News, Hacks, Tips, Tutorials, Plugins and Themes</description>
	<lastBuildDate>Mon, 21 May 2012 22:48:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Top Level Menu In WordPress 2.7</title>
		<link>http://wpengineer.com/475/top-level-menu-in-wordpress-27/</link>
		<comments>http://wpengineer.com/475/top-level-menu-in-wordpress-27/#comments</comments>
		<pubDate>Tue, 09 Dec 2008 13:20:40 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
				<category><![CDATA[WordPress Hacks]]></category>
		<category><![CDATA[Menu Icon]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Plugin]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Plugins]]></category>

		<guid isPermaLink="false">http://wpengineer.com/?p=475</guid>
		<description><![CDATA[I explained in one of my previous posts how to add a nice icon to your Plugin in the backend are of WordPress 2.7. Some of my readers on my German blog asked how to add an icon to menus in the top level. I thought there are more readers interested to know about it, [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://wpengineer.com/wp-content/uploads/wp27_mymenu.png" alt="" title="wp27_mymenu" width="261" height="139" class="alignright size-full wp-image-476" /><br />
I explained in one of my <a href="http://wpengineer.com/how-to-improve-wordpress-plugins/">previous posts</a> how to add a nice icon to your Plugin in the backend are of WordPress 2.7. Some of my readers on my German blog asked how to add an icon to menus in the top level. I thought there are more readers interested to know about it, therefore I will show it here including a hover effect for the icon.<br />
<span id="more-475"></span></p>
<h3><code>add_menu_page()</code></h3>
<p>The function <code>add_menu_page()</code> exists since the beginning of WordPress and got a parameter added in WordPress 2.7 &#8211; <code>$icon_url</code>.</p>
<pre lang="php">
add_menu_page( $page_title, $menu_title, $access_level, $file, $function = &#039;&#039;, $icon_url = &#039;&#039; )
</pre>
<p>This parameter can either send a path of the icon or a <code>div</code>, which can be addressed via CSS style. Additionally I like to show you how to implement the hover effect, which is standard in version 2.7.</p>
<h3>Plugin example</h3>
<p>Here is a little example to understand. I created the Plugin as you can see below and put it in the folder <code>/plugins/</code> of the WP installation.<br />
&rarr; Plugins<br />
&nbsp;&nbsp;&nbsp;&rarr; test<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&rarr; css<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&rarr; style.css<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&rarr; images<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&rarr; fb_menu.png<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&rarr; test.php</p>
<p>The Plugin includes the function to create the menu item in the top level area. Therefore we deliver the value <em>div</em> as last parameter.<br />
In addition we call the function via hook, so that the menu item will be created and the content of the function will be available.</p>
<pre lang="php">
function add_menu_page_in_27() {
	add_menu_page(__(&#039;Test&#039;, &#039;test&#039;), __(&#039;Test Description&#039;, &#039;test&#039;), 9, basename(__FILE__), &#039;&#039;, &#039;div&#039;);
}

add_action(&#039;admin_menu&#039;, &#039;add_menu_page_in_27&#039;);
</pre>
<h3>Icon via CSS Sprites</h3>
<p><img class="alignright" src="http://bueltge.de/wp-content/images/wp27/fb_menu.png" alt="Menu Icon for menu WordPress 2.7" /><br />
Now the HTML is in the backend and we use CSS to create the icon. I use the possibility of <a href="http://www.alistapart.com/articles/sprites/">CSS Sprites</a>.</p>
<p>I add an icon into the Plugin, which contains both conditions. See image on the right.</p>
<p>The associated CSS looks like below, which I placed in the folder css of the Plugin.  Thereby the ID of the menu item will be created by the name of the file &#8211; <code>toplevel_page_test</code> = <code>toplevel_page_</code> + <code>test.php</code>.</p>
<pre lang="css">
#adminmenu #toplevel_page_test div.wp-menu-image {
	background: transparent url(&#039;../images/fb_menu.png&#039;) no-repeat scroll -1px -33px;
}
#adminmenu #toplevel_page_test:hover div.wp-menu-image,
#adminmenu #toplevel_page_test.wp-has-current-submenu div.wp-menu-image,
#adminmenu #toplevel_page_test.current div.wp-menu-image {
	background: transparent url(&#039;../images/fb_menu.png&#039;) no-repeat scroll -1px -1px;
}
</pre>
<pre lang="php">
wp_enqueue_style( &#039;test_css&#039;, plugins_url( $path = &#039;/test/css/style.css&#039;), array() );
</pre>
<h3>Conclusion</h3>
<p>This is a clear and neat solution, which can be also integrated into small functions, if you query of wp-version basis.</p>
<pre lang="php">
if ( version_compare( $wp_version, &#039;2.6.999&#039;, &#039;&gt;&#039; ) ) {
 // since Version 2.6.999
} else {
 // less than Version 2.6.999
}
</pre>
<h3>Download</h3>
<p>You can donwload this example on my private blog - <a href="http://bueltge.de/menu-seite-ab-wordpress-27-hinzufuegen/845/#download">download page</a><br />
<hr /><a href="http://wpplugins.com/plugin/281/snippets" title="More informations about this plugin for WordPress"><img src="http://wpengineer.com/wp-content/themes/wpe-3/images/snippets-125-125.png" height="90" alt="WordPress Snippet Plugin" /></a> <a href="http://xtreme-theme.com"><img src="http://wpengineer.com/wp-content/uploads/feed-banner-2.jpg" alt="Xtreme One WordPress Framework"/></a><br />
&copy; <a href="http://wpengineer.com/">WP Engineer Team</a>, All rights reserved <small>(Digital Fingerprint: WPEngineer-be0254ce2b4972feb4b9cb72034a092d)</small></p>
]]></content:encoded>
			<wfw:commentRss>http://wpengineer.com/475/top-level-menu-in-wordpress-27/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>

