Issue with contextual help overwriting existing content

I’m missing something here:

function page_help($contextual_help, $screen_id, $screen) {

if ($screen_id == 'page') {

    $contextual_help = '
    <h5>Shortcodes</h5>
    <p>Shortcodes help</p>
    '.$contextual_help;

    return $contextual_help;
}

elseif ($screen_id == 'post') {

    $contextual_help = '
    <h5>Post help</h5>
    <p>Help is on its way!</p>
    '.$contextual_help;

    return $contextual_help;
}
}       

add_filter('contextual_help', 'page_help', 10, 3);

The code is inserting into the correct screens but I am having two issues:

Read More
  1. The code is inserting at the top, I’d like it at the bottom.

  2. The code is deleting the help from all other screens except those mentioned above.

Thanks in advance for your tips!

Niels

Related posts

Leave a Reply

1 comment

  1. In order to not delete help from all other screens, you need to always return the contextual help text, otherwise your filter doesn’t return anything for non-page/post screens and so nothing will show up. Move the return to the bottom of the function, outside of your if/else. Also, the original contextual help is being concatenated to the end of your custom message, so move it to the front to have your text put at the bottom. Thus:

    function myprefix_page_help($contextual_help, $screen_id, $screen) {
    
      if ($screen_id == 'page') {
        $contextual_help = $contextual_help.'
        <h5>Shortcodes</h5>
        <p>Shortcodes help</p>';
      }
    
      elseif ($screen_id == 'post') {
        $contextual_help = $contextual_help.'
        <h5>Post help</h5>
        <p>Help is on its way!</p>';
      }
    
      return $contextual_help;
    }       
    
    add_filter('contextual_help', 'myprefix_page_help', 10, 3);