Larger Lead Paragraph on Posts
Makes the first paragraph of every blog post slightly larger, a classic magazine touch that draws readers into the article.
Opens WPIDE on
Code
add_filter( 'the_content', function ( $content ) {
if ( ! is_singular( 'post' ) || ! in_the_loop() || ! is_main_query() ) {
return $content;
}
$result = preg_replace_callback( '/<p(?=[\s>])([^>]*)>/i', function ( $m ) {
if ( preg_match( '/\sclass=(["\'])/i', $m[1] ) ) {
return '<p' . preg_replace( '/\sclass=(["\'])/i', ' class=$1wpide-lead ', $m[1], 1 ) . '>';
}
return '<p class="wpide-lead"' . $m[1] . '>';
}, $content, 1 );
return null === $result ? $content : $result;
}, 20 );
add_action( 'wp_head', function () {
if ( is_singular( 'post' ) ) {
echo '<style>.wpide-lead{font-size:1.2em;line-height:1.6;}</style>' . "\n";
}
} );
Notes
Change the font size in the style rule at the bottom of the snippet.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.