Support » Fixing WordPress » How to add content into <P></P> around <?php the_content(); ?>

  • WPChina

    (@wordpresschina)


    I want to add the name of my blog with a colon at the beginning of each of my posts. However, when I add it, it always is one online above my content.

    I want it to look like:

    MyBlogName.com: Post starts here…

    Why is it a line above? Because the content in “the_content” is automatically placed with <p> and <p>. This is really aggravating! Ahh!

    How can I easily add my blog name (or any content) right after that first <p> tag and before my content starts? What can I change in <?php the_content(); ?> ? I also do not want to add the name in the post when I write it, because in the future I also want to add the date and othet items…

    I would be happy to hardcode my blog name into the file that sets the <p> tag, but I have not been able to find the file in WordPress…

    Tks for your help!

Viewing 6 replies - 1 through 6 (of 6 total)
  • I believe there are some run-in CSS properties that you can set. See this page for a little digestion.

    Another way to approach might be with a simple plugin.

    Maybe something like

    add_filter('the_content', 'addMyName ',99);
    
    function addMyName ($content) {
       $content = get_bloginfo('show').": ".$content;
       return ($content);
    }

    Note: no coffee yet, so I might be all wet, but it is something to consider.

    WPChina

    (@wordpresschina)

    Thanks for the tips. I have not gotten it working yet, but this is what I’m using and I hope it’s close:

    <?php
    /*
    Plugin Name:  addMyName
    */
    function addMyName ($content) {
       $content = get_bloginfo('show').": ".$content;
       return ($content);
    }
    add_filter('the_content', 'addMyName ', 9);
    ?>

    Any ideas where I should go from here? CSS isn’t a great option for me since I also want it to work on the RSS feeds…

    Tks!

    Getting errors when activating? I see I left a trailing space… fixed below:

    add_filter('the_content', 'addMyName', 9);

    When testing, be sure to disable any caching (wp-cache) and clear browser cache as well.

    WPChina

    (@wordpresschina)

    Perfect, you’re correct that the trailing space was causing the problems. Now it works well.

    I’m trying now to integrate both the post date and some meta data into the space too. I am trying to add the following two:

    <?php echo get_post_meta($post->ID, "Mood", $single = true); ?>

    and

    <?php the_time(' F j, Y'); ?>

    Can I not add PHP directly to the code? I tried and it broke but I think I am very very close to getting it correctly.

    Tks for your help!

    Assuming both of your snippets work, just add ’em in, but without the <?php tags.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘How to add content into <P></P> around <?php the_content(); ?>’ is closed to new replies.