WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] add something to the_content (4 posts)

  1. Alisko
    Member
    Posted 4 years ago #

    hi,
    i have a problem with the_content.
    i want to add a div to the_content so i have created a function

    function like_content($content) {
    	global $post;
    		$content = "<div class=\"ikaz\">";
    		$content .= "hello all";
    		$content .= "</div>";
    		$content .= $post->post_content;
    return $content;
    }
    add_filter( 'the_content', 'like_content' );

    it works good but not formatting because of $post->post_content. what can i do for formatting it?

  2. Alisko
    Member
    Posted 4 years ago #

    i solved the problem like that. i dont use $post->post_content. it is unnecessary. anyway you get formated content from the function.

    function like_content($content) {
    	global $post;
                    $original = $content;
    		$content = "<div class=\"ikaz\">";
    		$content .= "hello all";
    		$content .= "</div>";
    		$content .= $original;
    return $content;
    }
    add_filter( 'the_content', 'like_content' );
  3. Ciprian Popescu
    Member
    Posted 4 years ago #

    That's what I was looking for for a while now. You could also assign the content using get_the_content() function to a variable, then concatenate it with your desired content.

    But always, when using $content .= without first reading it into a variable, will add your content at the beginning of the post's content. Been through that.

  4. Nic Windley
    Member
    Posted 3 years ago #

    Hmm, I'm having problems getting this to work. Just created a new post here about it;

    http://wordpress.org/support/topic/407300?replies=1#post-1542139

Topic Closed

This topic has been closed to new replies.

About this Topic