7

I have a multi-author website and I use the WyPiekacz plugin to require that authors add 1-5 tags, select only a single category, and include a featured image (and require minimum dimensions for the featured image).

WyPiekacz also can restrict title/content min/max length. WyPiekacz is great, but it will only tell the author after they have done something wrong, not let them know the requirements before they make a mistake.

I would like to be able to add a note/reminder to each meta box to guide the author. Currently I have written the notes directly into the wordpress files. Here is a screen shot of my addition.

Tags Meta Box Note Wordpress

Featured image meta box located in wp-admin/includes/post.php Tags and categories boxes located in wp-admin/includes/meta-boxes.php

I would like to include these notes in the functions.php file or as settings in WyPiekacz.

I am not a coder, so any assistance would be greatly apprectiated.

1
  • please don't forget to accept answers which solve your problem. It credits those who help you, and also takes it off the unanswered pile. Commented Apr 15, 2012 at 1:07

3 Answers 3

7

You should never edit the core files of WordPress.

Instead you should only ever edit Plugin files and or Theme files (Plugins or Themes folder)

One of the easiest was to achieve this would be via jQuery;

jQuery('<div/>', {
    id: 'your-note',
    text: 'Add up to 5 tags...etc'
}).appendTo('#tagsdiv-post_tag .inner');

Save the above into a alerts.js file (or name it whatever you want). Place this file in your theme folder /theme_name/js/ for organizational purposes.

Then in your functions.php file paste;

function load_my_alerts(){
      wp_register_script( 
        'my_alerts', 
        get_template_directory_uri() . '/js/alerts.js', 
        array( 'jquery' )
    );
    wp_enqueue_script( 'my_alerts' );
}
add_action('admin_enqueue_scripts', 'load_my_alerts');

This will enqueue and load your alerts.js file only in the admin section of your site and as such it will then apply your jQuery by appending a div with an ID selector of your choice followed by your desired text.

This part ('<div/>', { will create a self-enclosed div for you, i.e. <div id="your-note">your note here...</div>

UPDATE

You might in effect try this as a template for multiple items;

jQuery(document).ready(function($){

$('<div/>', {
    id: 'xxx',
    text: 'yyy'
}).appendTo('#tagsdiv-post_tag .inner');

$('<div/>', {
    id: 'aaa',
    text: 'bbb'
}).appendTo('#some_other_element .example');

// etc...

});
4
  • Thanks, but it doesn't seem to be working. I have done exactly what you mentioned, but the message did not show up. Do I need to do the complete jQuery part of the code for each meta box? or is there a more direct and efficient way? Commented Apr 14, 2012 at 21:02
  • That's pretty direct and efficient already - since what you are looking to do is essentially DOM manipulation. The alternative is to either use PHP DOMDocument manipulation or something like PHP Simple DOM Parser but the latter means you need to add-on a library, not to mention then write the code to manipulate the DOM. So unless anyone else knows of an easier way to hook a message into the Tags metabox that's simpler than using jQuery then that's probably the best bet. (IMO)
    – Adam
    Commented Apr 14, 2012 at 21:04
  • @TravisPflanz View the source whilst in your admin area and make sure your alerts.js file is loaded. If it does not exist then there is an error with your input. If it does exist, try updating with the code snippet above. jQuery(document).ready(function($){ //do your stuff here });
    – Adam
    Commented Apr 14, 2012 at 21:06
  • Thanks, The UPDATE part of the answer worked. Being that I also included a link to a help page, "text" was changed to "html". Commented Apr 15, 2012 at 4:39
3

Using the "admin_post_thumbnail_html" thumbnail filter would be the best way to add text to the Featured Image metabox and avoids using JavaScript / jQuery:

View the "admin_post_thumbnail_html" developer reference on wordpress.org

You'd use it by adding something like this to functions.php:

add_filter('admin_post_thumbnail_html', 'add_featured_image_text');
function add_featured_image_text($content) {
    return $content .= '<p>The Featured Image should be at least 1024px wide</p>';
}
1

First I'd like to re-iterate @userabuser. You should never edit the core files of WordPress. In fact, you should avoid editing plug-ins and themes (use a child-theme instead) since changes are lost on an update, and you should update!

I would follow the method outlined in these questions:

and de-register the existing metabox used (I think as @userabuser uses, the ID is #tagsdiv-post_tag). Then re-register it, allowing you to create a function which defines its insides as explained in the above posts.

For your purposes however, the function you want to mimic is post_tags_meta_box(), found here: http://core.trac.wordpress.org/browser/tags/3.3/wp-admin/includes/meta-boxes.php#L265

Simply use the contents of that function in your own custom call back, and edit to display your messages.

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.