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.

On the wordpress admin edit posts page, I want to display some custom content and script, underneath the meta box.

I want to hand code this as the various plugins I could use (advanced custom fields for instance) take too much control away, and I don't need an actual field to be saved.

So for example, I want to add this to the edit posts page:

<div class='mydiv'>
  <img src='someImage.png' alt='someImage'/>
  <script type='text/javascript'>alert('hello world!');</script>
</div>

That's pretty much it. Nothing fancy or that contains any editable content.

What hook or function do I need to use to achieve this?

Any help greatly appreciated

share|improve this question

1 Answer 1

up vote 2 down vote accepted

As found here:

http://codex.wordpress.org/Function_Reference/add_meta_box

/**
 * Calls the class on the post edit screen
 */
function call_someClass() 
{
    return new someClass();
}
if ( is_admin() )
    add_action( 'load-post.php', 'call_someClass' );

/** 
 * The Class
 */
class someClass
{
    const LANG = 'some_textdomain';

    public function __construct()
    {
        add_action( 'add_meta_boxes', array( &$this, 'add_some_meta_box' ) );
    }

    /**
     * Adds the meta box container
     */
    public function add_some_meta_box()
    {
        add_meta_box( 
             'some_meta_box_name'
            ,__( 'Some Meta Box Headline', self::LANG )
            ,array( &$this, 'render_meta_box_content' )
            ,'post' 
            ,'advanced'
            ,'high'
        );
    }


    /**
     * Render Meta Box content
     */
    public function render_meta_box_content() 
    {
        ?>
        <div class='mydiv'>
          <img src='someImage.png' alt='someImage'/>
          <script type='text/javascript'>alert('hello world!');</script>
        </div>
        <?php

    }
}
share|improve this answer
    
that did the job, thanks very much :) –  jammypeach Mar 30 '12 at 15:34
2  
Love it when people use my Codex samples - proves that not all is for nothing :) - even when my sample code could be better. +1 –  kaiser Mar 30 '12 at 15:53

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.