Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Is there a way to force users to write a page title before publishing? I have found example of requiring post titles, but not page titles.

share|improve this question
1  
Can you show the examples you found for posts? Posts and pages are more or less the same. –  hampusn Sep 14 '12 at 10:44
    
Yes, this plugin seems to do the job for posts wordpress.org/extend/plugins/force-post-title –  Cody Sep 14 '12 at 14:16
    
Okey, so that plugin actually only checks the field with javascript, so it's not bulletproof. If that is not an issue, you can edit that plugin with one word to change it from posts to pages. If you need it for both posts and pages, you can just add one row instead. I'll post it as an answer since it will actually work. –  hampusn Sep 16 '12 at 6:37
add comment

1 Answer 1

up vote 1 down vote accepted

Start with downloading the plugin called Force Post Title.

Here's the plugin with one row (2 with the comment line) added to the bottom, based on our comments.

What happens is that a small jQuery script is added to the page Create Post/Page. The script will check if the title field is empty when the user clicks the submit button.

Since this is such a small plugin, you could easily modify it and copy it to your functions.php. That way, you won't have to edit an existing plugin which will give you a headache once you update it later on.

I should also mention that I found something (a filter) that could work in wp-includes/post.php, row 2489. I did some quick testing without any results though.

/*
Plugin Name: Force Post Title
Plugin URI: http://appinstore.com
Description: Forces user to assign a Title to a post before publishing 
Author: Jatinder Pal Singh
Version: 0.1
Author URI: http://appinstore.com/
*/ 
function force_post_title_init() 
{
  wp_enqueue_script('jquery');
}
function force_post_title() 
{
  echo "<script type='text/javascript'>\n";
  echo "
  jQuery('#publish').click(function(){
        var testervar = jQuery('[id^=\"titlediv\"]')
        .find('#title');
        if (testervar.val().length < 1)
        {
            jQuery('[id^=\"titlediv\"]').css('background', '#F96');
            setTimeout(\"jQuery('#ajax-loading').css('visibility', 'hidden');\", 100);
            alert('POST TITLE is required');
            setTimeout(\"jQuery('#publish').removeClass('button-primary-disabled');\", 100);
            return false;
        }
    });
  ";
   echo "</script>\n";
}
add_action('admin_init', 'force_post_title_init');
add_action('edit_form_advanced', 'force_post_title');
// Add this row below to get the same functionality for page creations.
add_action('edit_page_form', 'force_post_title');
share|improve this answer
    
Great! Thank you very much :) –  Cody Sep 16 '12 at 10:29
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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