Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I've managed to add my own menu to the admin bar. I want the first menu item to link to my theme's options page.

For example, is this 100% bulletproof or is there a direct method?

echo '<a href="'.get_admin_url().'admin.php?page=functions.php">Theme Options</a>';
share|improve this question

2 Answers 2

up vote 1 down vote accepted

Assuming the installation will never have a plugin register a page with that same name it should be safe, i'd suggest giving your registered page a uniquely prefixed name, and secondly if the page name refers to your theme's functions file wouldn't it then be calling the file directly(you shouldn't ever be calling the theme functions file directly).

You can actually pass get_admin_url and also admin_url the path to append, to use it like this..

echo get_admin_url( null, 'admin.php?page=functions.php' );

or similarly..

admin_url( 'admin.php?page=functions.php' );

No need for concatenation, and of course add the link html back as appropriate(left that out for brevity).

Another suggestion would be to not use the file name as the page value you registered, i keep seeing plugin's do it, and it's always driven me nuts, it makes more sense to just pass the page registration code a unique string, and not a filename(usually done using __FILE__ which i personally find ugly and hacky).

That would be my initial observations, ideally i'd like to see the code that registers the page and know where that registration code sits, ie. what file.

share|improve this answer

How about this:

echo "<a href='".admin_url('/admin.php?page=functions.php)."'>Theme Options</a>";

Codex for admin_url. Btw, are you adding a menu/submenu page for your custom theme options? You can use its slug here.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.