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 want to show some detail information on specific (for e.g. category=3) posts.

Therefore I use the following coding:

function postinfo_head() {

    global $post;
    $script = <<< EOF
<script type='text/javascript'>
    jQuery(document).ready(function($){
        $('.post-info').hide();
        $('.open-post-info').click(function() {
            var id = $(this).attr('id');

            $('.post-info-' + id).slideToggle("medium", function() {
                $(this).prev().toggleClass("toggled");
            }); 

            return false;
        });
    });       
</script>
EOF;
    echo $script;
    postinfo();
}
add_action('wp_head', 'postinfo_head');

function postinfo() {
    global $post;
    echo '<p class="open-post-info" id="'. $post->post_name .'">Details</p>';
    echo '<div class="post-info post-info-'. $post->post_name .'">';
    echo '<ul>';
    ... some detail fields
    echo '</ul>';
    echo '</div>';
}

Unfortunately the output is shown somewhere else (on top-left of the site - over the header img). How is it possible to show this coding below the header of a post?

I would reluctantly edit the template, if there is an other option of getting this to work.

BR, mybecks

share|improve this question
add comment

1 Answer 1

up vote 1 down vote accepted

You shouldn't inject postinfo() in the <head> section (that's what happens when you use the wp_head hook).

If you do not want to edit templates, I'd suggest you use the wp_footer hook instead, and append the postinfo to your header div with jQuery, e.g.:

$('.post-info').appendTo('#header');

share|improve this answer
    
thanks, that worked. –  mybecks Jan 15 '13 at 13:55
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.