Add Content at the Begining of the Existing Content in WordPress Post

WordPress allows custom filter function to add additional content to the beginning of the existing content from your “function.php” file without writing anything directly in the “single.php” file or “page.php” file.

Add the following code in your function.php file in the theme folder

function add_custom_content_to_the_content( $content ) {
    $custom_content = 'YOUR CONTENT GOES HERE';
    $custom_content .= $content;
    return $custom_content;
}
add_filter( 'the_content', 'add_custom_content_to_the_content' );

Replace ‘YOUR CONTENT GOES HERE’ with your custom content, so that it will be displayed at the beginning of the content. It will be good for those who are trying to add an advertisement script on the content page.

If you want the new content only in the single post page use the condition “is_single()” inside the function see the code

function add_custom_content_to_the_content( $content ) {
 if ( is_single() ) {
    $custom_content = 'YOUR CONTENT GOES HERE';
    $custom_content .= $content;
    return $custom_content;
 } else {
    return $content;
 }
}
add_filter( 'the_content', 'add_custom_content_to_the_content' );

Related Posts

Leave a Comment

DON’T MISS OUR GIVEAWAYS!
Subscribe To Newsletter
Subscribe to our newsletter and get all the latest updates offers and giveaways right in your inbox.
Subscribe
Give it a try, you can unsubscribe anytime.
close-link

Join Free Giveaway!

Subscribe to our newsletter to get latest offers and giveaways!
SUBSCRIBE
close-link