6

I'd like to add my own button link next to these two. Is this possible?

enter image description here

2
  • 3
    Why was this downvoted?
    – kaiser
    Commented Aug 15, 2011 at 18:27
  • Any reason you can't just hook into contextual help (i.e. the Help tab)? Commented Aug 15, 2011 at 19:47

4 Answers 4

4

The HTML

echo '<div id="screen-meta-links">';
echo ' <div id="contextual-help-link-wrap" class="hide-if-no-js screen-meta-toggle">';
echo '  <a href="#" id="your-own-button" class="show-settings">Text for your button</a>';
echo ' </div>';
echo '</div>';
echo '<br style="clera:both" />';

echo '<div id="your-button-content" class="your-button-hide">';
// your content goes here
echo '</div>';

And you need some custom JavaScript

jQuery(document).ready( function($){

$( '.your-button-hide' ).each(
  function(e){
    $( this ).hide();
  }
);

$( '#your-own-button' ).click(
  function( e ){
    e.preventDefault();

    $( '#your-button-content' ).toggle();

    var hasclass = $( '#your-own-button' ).hasClass( 'screen-meta-active' );
    if( hasclass ){
      $( '#your-own-button' ).removeClass( 'screen-meta-active' );
    } else {
      $( '#your-own-button' ).addClass( 'screen-meta-active' );
    }
  }
);

});

The HTML part adds the button, the JavaScript adds the functionality.

The complete code could look like this:

add_action( 'admin_menu', 'register_backendpage', 10, 0 );

function register_backendpage() {
  $pagehook = add_management_page(
    'Your backend page',
    'Your backend page',
    'manage_options',
    'a-menu-slug-of-your-choice',
    'backendpage_callback',
    false,
    'bottom'
  );

  add_action( 'load-' . $pagehook, 'enqueue_button_script', 10, 0 );
}

function backendpage_callback() {

    // output your button here, see code above

    echo '<div class="wrap">';
    /*
     * the rest of your page content
     */
}

function enqueue_button_script() {
    // the js above
    wp_enqueue_script( 'your-button-script', ... );
}
3

Not sure why this question was dismissed so quickly. It's actually a valid question, and would be really useful to be able to add a button up there, or even edit the content of each screen option.

I know this is an old question, but...

If you want it to just add a button up there that would link somewhere else. You could just add some jQuery to add the button.

jQuery("#screen-meta-links").append('<div id="contextual-help-link-wrap" class="hide-if-no-js screen-meta-toggle" style=""><a href="link.html" id="contextual-help-link" class="show-settings">My New Button</a></div>');

Now if you actually want that button to work in the same way as the other buttons, you would need to dig into the admin files.

The file you are looking for is:

wordpress\wp-admin\includes\screen.php

1

I have written a simple and exact clean solution for adding your own such button:

class TmMS_Controller extends TmMS {

    //...

    public function init() {
        //...            
        add_action('admin_footer', array(&$this, 'admin_footer'));
        // ...
    }



    public function admin_footer() {
    if (empty($_GET) OR (isset($_GET['post_type']) AND $_GET['post_type'] == 'post')) {
        if ($_SERVER['SCRIPT_URI'] == admin_url('edit.php')) {
            ?>
            <script type="text/javascript">
                jQuery(function() {
                    jQuery('#screen-meta-links').append('<div class="hide-if-no-js screen-meta-toggle" id="mail-subscriber-options-link-wrap" style=""><a aria-expanded="false" aria-controls="screen-options-wrap" class="show-settings" id="mail-subscriber-settings-link" href="#mail-subscriber-options-wrap">Newsplus</a></div>');
                    var mail_subscriber_options_wrap = jQuery('#mail_subscriber_options').html();
                    jQuery('#mail_subscriber_options').remove();
                    jQuery('#screen-meta').append(mail_subscriber_options_wrap);
                });

            </script>
            <?php
            $this->draw_prepared_posts_content();
        }
    }
}

    public function draw_prepared_posts_content() {
        $data = array();

        echo $this->draw_html('admin/prepared_posts_content', $data);
    }

    // ...

}

$tm_ms_controller = new TmMS_Controller();
add_action('init', array(&$tm_ms_controller, 'init'), 1, 999);

Add css instructions somewhere:

#mail-subscriber-options-link-wrap {
float: right;
height: 23px;
padding: 0;
margin: 0 0 0 6px;
font-family: sans-serif;
}

#mail-subscriber-options-link-wrap {
    -webkit-border-bottom-left-radius: 3px;
    -webkit-border-bottom-right-radius: 3px;
    border-bottom-left-radius: 3px;
    border-bottom-right-radius: 3px;
}

/* screen options and help tabs */
#mail-subscriber-options-link-wrap {
    border-right: 1px solid #d1e5ee;
    border-left: 1px solid #d1e5ee;
    border-bottom: 1px solid #d1e5ee;
    background: #eff8ff;
    background-image: -webkit-gradient(linear, left bottom, left top, from(#def1ff), to(#eff8ff));
    background-image: -webkit-linear-gradient(bottom, #def1ff, #eff8ff);
    background-image:    -moz-linear-gradient(bottom, #def1ff, #eff8ff);
    background-image:      -o-linear-gradient(bottom, #def1ff, #eff8ff);
    background-image: linear-gradient(to top, #def1ff, #eff8ff);
}

#mail-subscriber-options-posts{
    padding: 0;
    margin: 0;
}

Screens: Result of script working code architecture function to generate html

0

Is this possible?

Not without some JavaScript.

Will it be possible?

Those two tabs will be converted into a menu in the admin bar in WP 3.3. Check out the beta.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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