WordPress.org

Ready to get started?Download WordPress

Forums

Automatically bold first paragraph of content? (5 posts)

  1. graeme_au
    Member
    Posted 3 years ago #

    I need to automatically bold the first paragraph of each article for every post on my blog, but not sure how to do so. Any ideas? Thanks.

  2. aravindajith
    Member
    Posted 3 years ago #

    You can use CSS3 :first-child pseudo-class to achieve this.
    http://www.w3schools.com/css/pr_pseudo_first-child.asp

    It won't work in IE and old browsers though.

  3. Aga
    Member
    Posted 3 years ago #

    1. Automatically add a class (e.g.: class="lead") to your first paragraph, you can do it this way:

    function first_paragraph($content){
    	return preg_replace('/<p([^>]+)?>/', '<p$1 class="lead">', $content, 1);
    }
    add_filter('the_content', 'first_paragraph');

    source: http://36flavours.com/2009/08/wp-add-class-name-to-first-paragraph-in-blog-post/comment-page-1/#comment-994

    2. In your style sheet add:

    p.lead {
      font-weight: bold;
    }
  4. danapalooza
    Member
    Posted 3 years ago #

    Not working at all for me.

    I know that the code is being parsed because when I took the <?php bit off of the front end of the file the contents of the file showed up at the top of my site.

  5. danapalooza
    Member
    Posted 3 years ago #

    My mistake! It was a conflict with a plugin that was preventing the function from formatting the post.

Topic Closed

This topic has been closed to new replies.

About this Topic