Skip to content

Instantly share code, notes, and snippets.

@evansolomon
Created August 24, 2012 07:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evansolomon/3446970 to your computer and use it in GitHub Desktop.
Save evansolomon/3446970 to your computer and use it in GitHub Desktop.
Only show the first paragraph of posts on a WordPress front page
<?php
/*
Plugin Name: Front page first paragraph
Plugin URI: http://example.com/
Description: Only use the first paragraph of posts on the front page
Version: 1.0
Author: Evan Solomon
Author URI: http://evansolomon.me
*/
/**
* Copyright (c) 2012 Evan Solomon.
*
* Released under the GPL license
* http://www.opensource.org/licenses/gpl-license.php
*
* This is an add-on for WordPress
* http://wordpress.org/
*
* **********************************************************************
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* **********************************************************************
*/
function es_front_page_first_paragraph( $content ) {
if ( ! is_home() )
return $content;
$regex = '/<p>(.*?)<\/p>/';
preg_match( $regex, $content, $match );
if ( ! $match )
return $content;
return $match[0];
}
// Run this after wpautop()
add_filter( 'the_content', 'es_front_page_first_paragraph', 20 );
Copy link

ghost commented Aug 24, 2012

Strange, but I have only shown the second paragraph, not the first. Just write three paragraphs + picture.
How to fix?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment