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.

I am trying to build a plugin for showing a pie diagram based on the number of those categories which have maximum posts. This diagram is a meta box in post editing page. Here is my source of inspiration: jquery charts

Most of the way the function works is same but I added some hooks to add it into meta box. Here is my code:

add_action( 'add_meta_boxes', 'category_meta_box_add' );

function category_meta_box_add() {  
add_meta_box( 'my-meta-box-id', 'Category by Percentage', 'categories', 'post', 'normal', 'high' ); }  

function categories($atts,$content = '') { }        //full function is defined in link above
add_shortcode('mycategories', 'categories');
echo do_shortcode('[mycategories]');

This plugin on installing shows meta box without data, also gives error:

The plugin generated 721 characters of unexpected output during activation. If you notice “headers already sent” messages, problems with syndication feeds or other issues, try deactivating or removing this plugin.

How to resolve this?


Full plugin here

share|improve this question
Enable debugging, look at your logs. You probably have PHP Notices printing before the header are sent. –  s_ha_dum Mar 30 '13 at 15:06

1 Answer 1

up vote 1 down vote accepted

The problem might be because of this line:

echo do_shortcode('[mycategories]');

It should not stand alone like this in the plugin file, because this will show up before the headers are sent out. I guess you added this line just to check the output? Try to remove this line or encapsulate it with a relevant function. You could instead add the shortcode [mycategories] into the content of some post/page to test it.

You could replace this line

add_meta_box( 'my-meta-box-id', 'Category by Percentage', 'categories', 'post', 'normal', 'high' );  


add_meta_box( 'my-meta-box-id', 'Category by Percentage', 'category_meta_box_html', 'post', 'normal', 'high' );  

and add this function:

function category_meta_box_html(){
    echo do_shortcode("[mycategories]");

to display the graph inside the metabox.

share|improve this answer
I have removed that last 2 lines. The error is gone, but I am not able to obtain that pie diagram. Box is present with arrow sign without anything in it. I am not getting how to call this function. –  10wtaylor Mar 30 '13 at 17:15
It gives this error when call this function: categories() ----Warning: Missing argument 1 for categories(), called in C:\xampp\htdocs\abcs\wp-content\plugins\infograph\infograph.php on line 86 and defined in C:\xampp\htdocs\abcs\wp-content\plugins\infograph\infograph.php on line 57----- Which argument do I pass? –  10wtaylor Mar 30 '13 at 17:19
categories() is a callback function for the shortcode, and takes $atts and $content=null as arguments. I updated the answer, to show you how you could use do_shortcode inside the metabox. –  birgire Mar 31 '13 at 12:59
Thanks Birgire! –  10wtaylor Mar 31 '13 at 17:40
It worked smoothly in localhost, but when I added same into main site, the place is empty. I can't figure it out. :( –  10wtaylor Mar 31 '13 at 18:41

Your Answer


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.