Archived topic
How to Add Subtitle Below the title of the Blog Post?
7 replies · Started by Prakhar on December 12, 2019
Actually I wanna add subtitle Below the title. Like My title be black and bold and subtitle is small than this and light. Please help me.
Hi there,
i explain how to in this topic:
You only need to follow steps in point 1.
I want to add this manually. I mean I don't want any plugin for this. I wanna do with the help of code. Please Help ASAP
You would need to use WordPress Custom Fields:
https://wordpress.org/support/article/custom-fields/
And Hook this code into site, as per the topic i linked to:
<?php
// Get custom field value
$subtitle = get_post_meta( get_the_ID(), 'your-custom-field', true );
// Display $subtitle if not empty
if ( ! empty( $subtitle ) ) {
echo '<p class="custom-subtitle">' . $content . '</p>';
}
?>
Change the your-custom-field slug to whatever you named your custom field.
Hi David,
I try to use the last solution (subtitles) and I use GeneratePress Child: functions.php. Is this the right place where I should insert the code?
It didn't worked yet.
Kind Regards,
Markus
Hi Markus,
Do you want to add the subtitle before the entry title in each single post?
If so, try add this code in a hook element, change the your-custom-field to the slug of your custom field.
<?php
// Get custom field value
$subtitle = get_post_meta( get_the_ID(), 'your-custom-field', true );
// Display $subtitle if not empty
if ( ! empty( $subtitle ) ) {
echo '<p class="custom-subtitle">' . $subtitle. '</p>';
}
?>
Tick the Execute PHP box, choose generate_before_entry_title as the hook, choose post > all posts as location.
Please refer to the screenshot below:
https://www.screencast.com/t/R3qY61cW0gv
If you want it to be at other spot on the site, here's the visual hook guide:
https://docs.generatepress.com/article/hooks-visual-guide/
Hi Ying,
Okay, that explanation helped. Thank you very much!!! Awesome.
Is there a possibility to adapt form and font size of this subtitle?
Kind Regards,
Markus
Is there a possibility to adapt form and font size of this subtitle?
You can use CSS to style the text. :)