Styling the intro paragraph
A few weeks back (actually 18 days), @karelgeenen asked me on Twitter how he could bold the text above the <!--more--> tag in WordPress, like the Dutch site Marketingfacts (which is actually built in Expression Engine).
I didn't know back then and this afternoon I decided to try and solve it for him. It turned out to be quite simple. I've made it into a simple plugin, called Yoast Style Intro, but you can also just add the code below to your themes functions.php.
The plugin wraps the intro in a span with class="yoast_intro", so you can style it by adding, for instance, the following code to your themes style.css:
.yoast_intro {
font-weight: bold;
}The code
Add this to your themes functions.php:
function yoast_style_intro($content) {
if (is_single() || is_page()) {
$content = '<span class="yoast_intro">'.$content;
$content = str_replace('<span id="more','</span><span id="more',$content);
return $content;
}
}
add_filter('the_content','yoast_style_intro',1,1);Or you can download the plugin here.
Be aware that if you use the filter the_content multiple times on a page, this plugin might give you trouble.



by Henri van den Hoof on 21 December, 2008 at 18:40
Smart and easy solution for a question I also had, but wasn't able to solve myself :-)
Have a great Xmass!
by Ryan on 22 December, 2008 at 00:09
Simple but elegant solution, thanks for this :)
by Chris Abernethy on 22 December, 2008 at 03:40
Looks pretty cool... could you use a static variable inside the yoast_style_intro() function to prevent problems when the_content is called multiple times?
by Abeon on 22 December, 2008 at 16:36
Great information!
I have been looking for a way to do this (got here by google).
Very simple solution to an annoying little problem, thanks :)
by achot on 24 December, 2008 at 20:10
thx for ur info.. :)
by Nihar on 25 December, 2008 at 09:08
Its a very simple tip but very effective. Thanks for the tip.
by Roger (frontaal.net) on 31 December, 2008 at 19:21
On my blog I use a simple CSS pseudo class selector to accomplish the same effect:
body.single div.entry-content p:first-child {font-weight:bold;}No need to edit php-files or add HTML-elements... Except when you also want bold text in IE6.
by Bobbink - 11 Internet on 5 January, 2009 at 11:14
Thanks for sharing!
by Paradox on 19 March, 2009 at 03:52
This does not seem to work on my blog. On the main page, no content appears under the headlines.
Yet on the full view, it appears as it normally should.
by dimaks on 24 October, 2009 at 14:56
being a novice in blogging, what could be the best possible benefits from making the intro part bold? just curious.. who knows i might use it. thanks!