Add Settings Link To Plugin On Plugins Page in WordPress

This is how to add a ‘Settings’ link under your plugin on the plugins page. The ‘Settings’ link will appear right next to the Deactivate link. If you are within a PHP class, do example 1. If your plugin is not within a PHP class, follow example 2.

Example 1: If your plugin is within a PHP class

Step 1:
Add this to your plugin file, in the constructor:

add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), array( $this, 'plugin_settings_link' ) );

Step 2:
Add this method to the class:

function plugin_settings_link($links) {
$url = get_admin_url() . 'options-general.php?page=yourplugin_options';
$settings_link = '<a href="'.$url.'">' . __( 'Settings', 'textdomain' ) . '</a>';
array_unshift( $links, $settings_link );
return $links;
}

Step 2:
Make the following changes to the code above.

Line 2: change yourplugin_options to your own plugin options page slug.

Line 3: change ‘textdomain’ to your own plugin’s text domain.

Example 2: If Not Within a PHP Class

If you’re plugin is NOT built with a PHP class, then use this instead:

function myplugin_settings_link( $links ) {
	$url = get_admin_url() . 'options-general.php?page=yourplugin_options';
	$settings_link = '<a href="' . $url . '">' . __('Settings', 'textdomain') . '</a>';
	array_unshift( $links, $settings_link );
	return $links;
}

function myplugin_after_setup_theme() {
     add_filter('plugin_action_links_' . plugin_basename(__FILE__), 'myplugin_settings_link');
}
add_action ('after_setup_theme', 'myplugin_after_setup_theme');

Make the following changes to the code above.

Line 2: change yourplugin_options to your own plugin options page slug.

Line 3: change ‘textdomain’ to your own plugin’s text domain.

See more: ,

We've 2 Responses

Questions and Comments are Welcome

Your email address will not be published. All comments will be moderated.

Please wrap code in "code" bracket tags like this:

[code]

YOUR CODE HERE 

[/code]