Support » Plugins » Hacks » Adding Image to end of last line

  • Hey Gang, maybe you can help me. I’m trying to add a tiny image to the end of the very last line of a post. I’ve got the function built so the image appears after each post, but my problem is, it appears on the next line and I can’t for the life of my get it on the same line.

    Here’s my function

    function new_default_content($content) {
    global $post;
        if ($post->post_type == 'blog') {
        $content .= '<p class="sig"><img src="url/images/LM.jpg"  /></p>';
        return $content;
    add_filter('the_content', 'new_default_content');

    And I’m getting this type of result:

    This is the end of the post

    But I want

    This is the end of the post [image]

    Any help would be greatly appreciated. It’s driving me bonkers.

Viewing 1 replies (of 1 total)
  • Moderator bcworkz


    First, drop the <p> tags, they pretty much guarantee your image will be on it’s own line. Further more, the passed post content almost assuredly has a closing </p> tag. Your <img> tag needs to be before this final tag to appear immediately after the end of the content text. Accurately inserting your tag using PHP string functions under all end conditions can be a bit tricky.

    That may take care of things, but there could be one more thing standing in the way, Images may, depending on the theme, default to display as CSS block elements. Yours will need to display as an inline element. There’s a few ways to do this, the easiest is to simply add this attribute to your <img> tag: style="display:inline;"

Viewing 1 replies (of 1 total)
  • The topic ‘Adding Image to end of last line’ is closed to new replies.