1

I'm trying to add a notice text that said "Please choose a category and add feature Image" text right above the editor so that they don't forget but I'm not sure how to do that so I would be really appreciate if I can get any help.

I've try every method I could find on the internet but it seems like they are a couple of years ago so it's not working for some reason.

I don't want any functionality, I just wanted to show a very simple text above the Title in the text editor so that they don't forget to include category and image.

1
  • are you using gutenberg or classic editor or some other editor all the same?
    – rudtek
    Commented Feb 7, 2022 at 4:38

1 Answer 1

1

Assuming you're using gutenberg you need to use javascript to do this. Here's the steps I would take. In your child theme you'll need to add some code.

  1. Add a new directory "js".

  2. In that directory add a new file called "alerts.js"

  3. In that file add this code: (this is the actual warning note)

    ( function( wp ) {
     wp.data.dispatch('core/notices').createNotice(
         'warning', // Can be one of: success, info, warning, error.
         'Please remember to add a featured image and choose a category.', // Text string to display.
         {
             isDismissible: true, // Whether the user can dismiss the notice.
             // Any actions the user can perform.
         }
     );
     } )( window.wp );
    
  4. Now tell WordPress that you want to use that code by enqueuing the JS in the child theme's functions.php:

     function alerts_enqueue() {
         wp_enqueue_script('alerts-script', get_stylesheet_directory_uri() . '/js/alerts.js');
     }
     add_action( 'enqueue_block_editor_assets', 'alerts_enqueue' );
    

If you're using the classic editor or another block editor this will not work.

I'd also suggest just requiring the featured image and/or category selection if you really want the users abide by the "rules". :)

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.