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.
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.
Share Improve this question edited Feb 24, 2022 at 16:14 fuxia♦ 107k38 gold badges255 silver badges459 bronze badges asked Feb 6, 2022 at 20:36 ziicoziico 1311 bronze badge 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
Reset to default 1Assuming 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.
Add a new directory "js".
In that directory add a new file called "alerts.js"
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 );
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". :)