If you look at the first paragraph of this post, you can see that it is slightly different from the rest of the entry in terms of style. It has a different font, colour and the size is bigger than usual.
This is one of the recent changes I’ve made in this site. Actually, I got inspired by Syahir’s website. At first, I thought it would be difficult implement that idea here. Then I got to know that there is nothing to deal with theme function! I can do this with a few lines of CSS and the rest things will go with writing posts.
Well, here is the trick. First I added this to my style sheet.
.firstp { font: 16px/21px Georgia; color: #573428; } |
Then, while writing posts, I just assign firstp class to the first paragraph. i.e <p class="firstp"> My first paragraph </p>.
Isn’t it cool? It is easy too! Try it yourself in your site, and show me your customizations.
Bonus: Short code
If you think it is difficult to add firstp attribute each time while writing posts, you can create a short code for that by adding this to your (child) theme’s functions.php file.
// short code for first paragraph function firstpara_shortcode( $atts, $content=null, $code="" ) { return '<span class="firstp">' . $content . '</span>'; } add_shortcode( 'firstpara', 'firstpara_shortcode' ); |
Here firstpara is the short code. So, just wrap your first paragraph with [firstpara] short code and it will take care of the rest things.
Example: [firstpara]This is the first paragraph of my weird post. Lorem ipsum dolor sit amet, consectetur adipiscing … .. .. elit. Donec nisi[/firstpara]
Note:
Beware that your first paragraph may not visible in excerpt if you use shortcode. So, I strongly recommend you to use P class attribute instead.
Follow these topics Graphene, WordPress
Short Link:


9 comments
Skip to comment form ↓
Tanya Demjanec
February 22, 2012 at 6:16 pm (UTC 5.5) Link to this comment
A great idea for adding a little customized style — without a lot of hassle.
Thank you, Prasanna!!!
Best,
-Tanya
Prasanna SP
February 23, 2012 at 10:14 am (UTC 5.5) Link to this comment
Thanks Tanya!
Luko
February 29, 2012 at 12:08 am (UTC 5.5) Link to this comment
Nice,
it can be applied in other themes also,
Thanks for sharing PHP code, works great!
Prasanna SP
February 29, 2012 at 4:31 pm (UTC 5.5) Link to this comment
Yes, it works with other themes as well.
Thanks Luko!
Richard
April 9, 2012 at 8:37 pm (UTC 5.5) Link to this comment
A very nice styling trick
Thankyou for leaving a comment on my site, it got me to have a look here, and I’m finding a few interesting tweeks that I can incorporate.
Richard
Prasanna SP
April 10, 2012 at 10:47 am (UTC 5.5) Link to this comment
Thanks for your comment Richard!
Ahmed
October 2, 2012 at 11:40 pm (UTC 5.5) Link to this comment
Hey
I am willing to change my current theme to Graphene and I am also willing to change its default post font to Book Antiqua or Georgia. How could I do this change.
Regards
Ahmed
Ahmed
October 17, 2012 at 12:11 am (UTC 5.5) Link to this comment
Hi
How can i change the whole post to Georgia from default font style? plz help
Regards
Ahmed
http://icabtutorial.com
Prasanna SP
October 19, 2012 at 7:13 pm (UTC 5.5) Link to this comment
Hi Ahmed! To change content text font to Georgia, go to Graphene Options –> Display –> Text Style Options and put georgia in Content Text –> Text font