0

I run a multi-author website and many of my users are forgetting to set a featured image for their post. This is a big problem as my theme depends highly on featured images to keep a consistent feel throughout the site.

I've found a plugin that allows for a default featured image to be set if the user doesn't set one but this is far from perfect.

Is there anyway to have an error message pop-up when the featured image is not set and the user tries to publish, or potentially disabling the ability to publish a new post until a featured image is assigned?

Ideally I'd like to find a solution that pops up before the page is reloaded, to limit the frustration of the user/avoid unnecessary steps and time wasted reloading the page.

Thanks, Paul

-1

you can hook yourself into save_post and check there if the image is present. if it is not there fire an admin_notice.

more here https://wordpress.stackexchange.com/a/15355/32776

http://codex.wordpress.org/Plugin_API/Action_Reference/save_post

Edit: I dont have the time to provide working code but here is a copy paste from the links above. i think that you have to figure what the field name is. maybe "thums" works.

as a start go to your functions.php

<?php
add_action( 'save_post', 'check_if_image_set' );

function check_if_image_set( $post_id ) {

    //verify post is not a revision
    if ( !wp_is_post_revision( $post_id ) ) {

        //http://codex.wordpress.org/Function_Reference/get_post_meta
        if ( get_post_meta($post_id, 'thumb', true) )

    }else{
           add_action('admin_notices', 'my_admin_notice');
        }

}

function my_admin_notice(){
    //print the message
    echo '<div id="message">
       <p>No Picture Set!!!</p>
    </div>';
    //make sure to remove notice after its displayed so its only displayed when needed.
    remove_action('admin_notices', 'my_admin_notice');
}
?>

Best Regards, Simon

  • Thanks for the reply Simon, are you able to provide a little more clarification as to exactly how I'm able to do this? – Paul Thomson May 13 '13 at 14:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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