WordPress.org

Ready to get started?Download WordPress

Forums

How to add content into <P></P> around <?php the_content(); ?> (7 posts)

  1. WPChina
    Member
    Posted 7 years ago #

    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!

  2. JeremyVisser
    Member
    Posted 7 years ago #

    I believe there are some run-in CSS properties that you can set. See this page for a little digestion.

  3. Chris_K
    Member
    Posted 7 years ago #

    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.

  4. WPChina
    Member
    Posted 7 years ago #

    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!

  5. Chris_K
    Member
    Posted 7 years ago #

    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.

  6. WPChina
    Member
    Posted 7 years ago #

    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!

  7. Chris_K
    Member
    Posted 7 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic