Sunday, September 4, 2011





Adding an Appearance sub-menu on Wordpress Admin


I dove head-first into the Wordpress a few month ago and have been swimming along with varied results ever since. Recently I've run into an annoying issue that I think is worth documenting for next time I need the solution to it.

The problem I've encountered requires adding a sub-menu page to the WP Admin built-in Appearance menu. There are vast amounts of information on adding option pages, new menu pages and even sub-pages. When you search for something like 'wordpress admin add sub-menu' (or anything else to that extent mentioning 'sub-menu' as it is the keyword in question) you'd probably end up with a bunch of tutorials and function reference pages guiding you to use the add_submenu_page function. Codex reference page for the function states that general usage being

add_submenu_page$parent_slug$page_title$menu_title$capability$menu_slug$function );


you just need to use an appropriate parent_slug for the desired WP Admin menu and

7. For Appearance: add_submenu_page('themes.php',...) 

Well, guess what... nothing happens when you do that. I've stumbled across a line of code on one of the many tutorials that was a small unexplained aside followed by the full tutorial that was a lot like numerous others. However, adapting that 'aside' line to my code did the trick!!

The solution:
instead of

add_submenu_page('themes.php',...)  

use

add_theme_page('your-theme-name',...) 

where 'your-theme-name' is, in fact, just the name of the theme you are adding the page for. The rest of the meat filling is the same as for any of the add_xxx_page functions.