1

I'm trying to add a "settings" link to my plugin on the plugins page. I used this code, which I found on various sites and also in the documentation, but it simply doesn't work (the link doesn't show).

What did I do wrong?

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

add_filter('plugin_action_links_' . plugin_basename(__FILE__), 'apd_settings_link');
1

The code is working and tested. Activate your plugin you will see the settings link

add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), 'apd_settings_link' );
function apd_settings_link( array $links ) {
    $url = get_admin_url() . "options-general.php?page=my-plugin";
    $settings_link = '<a href="' . $url . '">' . __('Settings', 'textdomain') . '</a>';
      $links[] = $settings_link;
    return $links;
  }
3
  • The code worked when I put in in my plugin main file. It seems like I had it in the wrong place before that. I included a file called init.php in my main file like so: require dirname( FILE ) . '/apd-init.php'; And there I put my code before, which didn't work. How is that? – TheKidsWantDjent Apr 22 '17 at 17:29
  • 1
    got the point. check plugin_basename(FILE) not showing your main plugin file :). define( 'EXAMPLE_ABSPATH', plugin_dir_path( FILE ) ); define( 'EXAMPLE__FILE__', FILE ); define( 'EXAMPLE_BASENAME', plugin_basename( Example__FILE__ ) ); in your main plugin file. and apd-init.php file change the plugin file to add_filter( 'plugin_action_links_' . 'EXAMPLE_BASENAME, 'apd_settings_link'); – Faysal Mahamud Apr 23 '17 at 5:51
  • Thank you, that was actually my problem. Calliing plugin_basename(FILE) from apd-init.php would give me the wrong file name. So I defined it the way you did in your example. – TheKidsWantDjent Apr 25 '17 at 15:41

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.