• Skip to primary navigation
  • Skip to main content
Sal Ferrarello
  • About Sal Ferrarello
  • Speaking
  • Connect
    Mastodon GitHub Twitter (inactive)
You are here: Home / Programming / WordPress Plugin Add Settings Link
WordPress Plugin Add Settings Link

WordPress Plugin Add Settings Link

Last updated on August 26, 2014 by Sal Ferrarello

Adding a Settings link to your plugin on the Plugin admin screen adds a bit of polish to your plugin. You’ve probably noticed many plugins include a Settings link right next to Deactivate and Edit. This is an easy feature to add.

These Settings links are particularly nice due to the variability in settings page locations within the WordPress menu. You’ll find settings pages under Settings, Tools, Dashboard, Media, Users, and Custom Top Level Menu Items. It can be very frustrating as a user seeking out the settings page, especially when the menu label does not match the plugin name.

How to Use This Code Snippet

  • Paste this code into the main plugin file (it can not be an include or require file within the plugin)
  • Modify options-general.php?page=my-plugin to match the URL ending for your settings page
add_filter('plugin_action_links_'.plugin_basename(__FILE__), 'salcode_add_plugin_page_settings_link');
function salcode_add_plugin_page_settings_link( $links ) {
$links[] = '<a href="' .
admin_url( 'options-general.php?page=my-plugin' ) .
'">' . __('Settings') . '</a>';
return $links;
}
view raw plugin.php hosted with ❤ by GitHub
Sal Ferrarello
Sal Ferrarello (@salcode)
Sal is a PHP developer with a focus on the WordPress platform. He is a conference speaker with a background including Piano Player, Radio DJ, Magician/Juggler, Beach Photographer, and High School Math Teacher. Sal can be found professionally at WebDevStudios, where he works as a senior backend engineer.

Share this post:

Share on TwitterShare on FacebookShare on LinkedInShare on EmailShare on Reddit

Filed Under: Programming Tagged With: WordPress, WordPress Plugin

Reader Interactions

Comments

  1. jarim says

    January 20, 2015 at 10:26 am

    Thanks a lot!!!!!!!!! you save my day 🙂

    Reply
  2. Darshan Saroya says

    February 24, 2019 at 11:25 pm

    Short and to the point.

    Reply
  3. Homa Pardazesh says

    April 7, 2019 at 12:29 pm

    Simple, Clean and usefull.
    you made my day 🙂

    Reply
  4. Isaac Fennell says

    July 1, 2019 at 11:35 am

    Rather than “adds a bit of polish”, I wish this was a requirement of ALL plugins. Either the link to settings, or say there are none. So much time wasted trawling through the admin menu…

    Reply
  5. Victoria says

    May 25, 2020 at 10:51 am

    Hi,

    It didn’t work for me until I changed the admin url to admin_url( 'admin.php?page=vw-postcode-checker' )
    instead of options-general.php

    But apart from that great tutorial. QUick and to the point.
    THank you

    Reply
    • Sal Ferrarello says

      May 26, 2020 at 11:17 am

      I’m glad this was helpful.

      I believe the URL is admin.php for top level menu items and options-general.php for sub-menu items found under the top-level Settings menu item.

      Clearly, there are exceptions to any rule (and I don’t know anything about your specific use-case) however as a rule I try to always put my settings in the sub-menu.

      Reply
  6. Justin says

    November 5, 2020 at 9:43 am

    Sal, I’m wondering if you could share code related to removing the settings link if the plugin is deactivated? In my plugin, I have 2 very specific functions (activate and deactivate) that have a triggered sequence of events. I’d like to CREATE the link during activation and REMOVE the link during deactivation.

    Reply
  7. Benson Karue says

    February 16, 2021 at 5:22 pm

    how to change the position of the menu item.

    For example, on my side it appeared like:

    Deactivate | Settings

    but for other plugins, it’s as shown below
    Settings | Deactivate

    probably “Settings | Deactivate”, comes with a better user experience(UX). Please let me know if there is away to make the arrangement of my links like the other plugins

    thanks

    Reply
    • Sal Ferrarello says

      February 21, 2021 at 11:11 am

      Hi Benson,

      In the salcode_add_plugin_page_settings_link() function we are appending the new link to end of the $links array with the code $links[] =.

      If we want to prepend the link and add it to the beginning of the array, you may be able to use array_unshift() instead (note: I’ve not tried this yet but it is where I would start).

      Reply
      • Kyle Elmore says

        July 28, 2021 at 1:05 pm

        array_unshift worked for me! New function would look like:

        function salcode_add_plugin_page_settings_link( $links ) {
                array_unshift(
                 	$links,
                 	'<a href="' .
                	admin_url('options-general.php?page=my-plugin') .
                	'">' . __('Settings') . '</a>'
            	);
        	return $links;
        }
        
        Reply
  8. Wajahat says

    August 3, 2021 at 12:48 am

    Thanks a lot!!! You Saved Me a lot of time a effort

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Copyright © 2023 · Bootstrap4 Genesis on Genesis Framework · WordPress · Log in