0

I'm using it to add a message to posts/pages/cpts, but it's also appearing on one screen of a plugin - so I need to remove it.

I have the screenID, but my knowledge-lacking efforts to add a conditional between the opening brace and echo in the code below produce a variety of errors.

add_action( 'edit_form_after_title', function( $post ) {
echo "<div class=\"add-message\">
<p>Message.</p>
</div><!-- /add-message -->";
});

1 Answer 1

1

It seems like it might be worth restricting your message specifically to the screens you want the message to appear on, rather than having it appear everywhere except a plugin page. The screen ids of "post" and "page" are self-explanatory; just add more "or" clauses with the double pipes and include any custom post types you want the message to appear on.

add_action( 'edit_form_after_title', function( $post ) {
$screen = get_current_screen();
if($screen->id == 'post' || $screen->id == 'page' || $screen->id == 'your_cpt_slug') {
echo "<div class=\"add-message\">
<p>Message.</p>
</div><!-- /add-message -->";
}
});

If instead you do want it to appear everywhere in the admin except your particular plugin screen ID, substitute that screen ID for 'screen_to_hide_on' below:

add_action( 'edit_form_after_title', function( $post ) {
$screen = get_current_screen();
if($screen->id != 'screen_to_hide_on') {
echo "<div class=\"add-message\">
<p>Message.</p>
</div><!-- /add-message -->";
}
});
1
  • 1
    @ WebElaine... thanks. Excellent. You've helped me to understand something which had befuddled me.
    – glvr
    Commented Dec 1, 2016 at 7:18

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.