Forums

current post data from shortcode - strange formatting (2 posts)

  1. superpotion
    Member
    Posted 5 months ago #

    Conventionally the post-meta (date, author, categories, etc) is placed above or below the post content. Instead I want to place it somewhere within the content by using a plugin that implements a shortcode.

    The business end of the plugin looks like this:

    add_shortcode("my-post-meta", "mypostmeta_handler");
    function mypostmeta_handler() {
      global $post;
      $postmeta_output  = '<div class="post-meta">';
      $postmeta_output .= 'Posted on ' . the_time('j F Y');
      $postmeta_output .= 'by ' . the_author_posts_link();
      $postmeta_output .= 'in ' . the_category(', ');
      $postmeta_output .= '</div>';
    
      return $postmeta_output;
    }

    In the browser I was expecting: Posted on 13 December 2011 by admin in Work, News. Instead, the constant strings appear in the browser in the correct position as a single, concatenated string: Posted on by in. But the post meta somehow detached itself from the div and displayed at the beginning of the content, also as a concatenated string: 13 December 2011adminWork, News

    What do I need to do to control it?

  2. superpotion
    Member
    Posted 5 months ago #

    I've deactivated other plugins and switched themes in case there's a content filter that's interfering, perhaps something like:

    add_filter('the_content', 'some_interfering_filter' );

    ...but to no avail. I'm guessing here, but could any filters in the core have this effect? If so, can I modify their behavior?

Reply

You must log in to post.

About this Topic