7

Trying to add a link to my admin menu (dashboard/backend) that leads to the frontend of wordpress, so I basically want a link in the menu that takes me to the blog.

I've found a couple of ways to add new stuff to the admin menu, but I haven't been able to link to the home_url, it seems like the admin menu only is designed to let you link to stuff within the wp-admin. Anyone that have succeeded with this?

Edit:
Tried with this: https://gist.github.com/792b7aa5b695d1092520

add_admin_menu_item('Overview',array( 
      'title' => 'View Site',
      'slug' => get_bloginfo('url')
  ));

Which gives me the link hxxp://myurl.com/myurl.com
With this plugin (hxxp://wordpress.org/extend/plugins/admin-menu-editor/), I get:
hxxp://myurl.com/wp-admin/www.test.com

7

you can create a function that redirects to the front-end like this:

function redirect_home_987(){
  wp_redirect( home_url() ); 
  exit;
}

and call that function in WordPress default add_menu_page function like this:

add_menu_page( 'redirecting', 'View Site', 'read', 'my-top-level-handle', 'redirect_home_987');

Hope this helps

  • Not sure if I understand you correctly. I've added this to my functions.php now: add_action('admin_menu', 'add_viewsite'); function add_viewsite() { add_menu_page( 'redirecting', 'View Site', 'read', 'my-top-level-handle', 'redirect_home_987'); } // Call this function for a "home" link function redirect_home_987(){ wp_redirect( home_url() ); exit; } Which gives me a link that looks like this: url.com/wp-admin/admin.php?page=my-top-level-handle – INT Jan 31 '11 at 14:15
  • 1
    I had the same problem - some of the headers had already been sent. Tried a few options; the only one that seemed to work (which I'm not really happy with) is combining the above with javascript, like this answer – Hobo Jul 7 '13 at 18:59
1

The name of site (top left, next to WP logo) links to front-end, is that not sufficient?

Also it would help if you included code that you had tried so far in the question.

  • Thanks for your reply. I removed the name of the site, since it broke the layout of my customized backend, so I need to implent a link to the front end in the menu instead. – INT Jan 30 '11 at 23:16
1

You cannot add items to the admin menus that point to external URLs, the menu addition functions do not support this, nor will they allow it.

However, if you attach a callback onto the admin_menu hook, you can insert some items yourself manually and totally overcome the non-external URL problem. I do this myself and i'm quite surprised noone has already pointed out the issue with external menu links.

I provided an example when answering Adding an Arbitrary Link to the Admin Menu?

Let me know if that helps.

  • In fact, this question seems to be an exact duplicate of this one. So it got my vote to close it! – Jan Fabry Feb 1 '11 at 11:12
  • @Jan Fabry - I was thinking that when i linked to the other question so i've also voted to close as duplicate (the user should also have the answer he/she is looking for now, so closing need not be considered a bad thing). – t31os Feb 1 '11 at 11:16
-1

just add ../ as slug prefix:

add_admin_menu_item('Overview',array( 
  'title' => 'View Site',
  'slug' => '../slug'          // relative url
));
  • 1
    Please edit your answer, and add an explanation: why could that solve the problem? – fuxia Oct 20 '17 at 12:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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