Would you like to automatically add a ‘Sponsored Post’ prefix to blog post titles in WordPress?
Once you start publishing sponsored posts, you must disclose which posts are sponsored. You could do this by adding the word ‘Sponsored’ to the post title or by adding a disclaimer in the body of the post.
In this article, we will show you how to automatically add a ‘Sponsored Post’ prefix to your post titles in WordPress.

Why Add Sponsored Post Prefix to Your Posts?
Once your WordPress blog starts to attract more traffic, you may start thinking about how to monetize it. You can use WordPress and blogging to make money online by doing what you love.
One way to do that is through sponsorships. This is where a company pays you to represent their product, talk about it, and promote it to your readers. The sponsorship may be for a single post or an ongoing relationship.
When publishing sponsored posts, it’s crucial to know about the laws in your area about disclosure.
For example, in the United States, a blogger who publishes a sponsored post must comply with the FTC’s Endorsement Guides. This includes disclosing whenever a post is sponsored.
One way to do that is to add a prefix to the title of every sponsored post.

We’ll show you how to do exactly that in this guide. It does involve the use of code snippets and custom fields, which may seem intimidating to beginners, but we’ll walk you through every step.
In this article, we will be using a custom field to add a ‘sponsored’ custom field to a post. This will give us a way of identifying which posts are sponsored and which aren’t.
Custom fields can be used to add any information related to the post, page, or any content type. This meta-information can be displayed in your theme.
To add the ‘Sponsored Post’ prefix to your titles, you’ll need to edit your WordPress theme files. We’ll do that by adding a custom code snippet to your theme’s functions.php file.
With that being said, let’s take a look at how to add a ‘Sponsored Post’ prefix to your post titles in WordPress.
How to Add a Sponsored Post Custom Field to Your Post
Start by opening one of your existing sponsored posts or creating a new one. The custom fields panel is normally located below the content editor. However, if you’ve never used custom fields before, then it will be hidden.
The way to display the custom fields meta box depends on whether you are using the block editor or the classic editor.
If you use the block editor, then you need to click on the three-dot menu at the top-right corner of the screen and select ‘Preferences’ from the menu.

This will bring up a Preferences popup where you need to go to the Panels section and then turn on the ‘Custom fields’ switch.
After that, click on the ‘Enable & Reload’ button to reload the post editor.

If you are still using the old WordPress classic editor, then you need to click the ‘Screen Options’ button on the top right corner of your screen.
This will open a menu where you need to check the box next to custom fields options.

The post editor will then reload.
When you scroll below the content editor you’ll be able to see the custom fields panel.

To add a new custom field, just type ‘sponsored’ in the Name text box.
In the next field, be sure that the Value is ‘true.’

Next, you need to save your post and scroll down to the custom fields meta box. You will notice that the custom field meta box is now showing a drop-down menu.
Next time you write a sponsored post, all you need to do is select ‘sponsored’ from the drop-down menu and enter ‘true’ in the Value field.

How to Add the Sponsored Post Prefix with a Code Snippet
After adding the sponsored custom field to your post, you need to add the code that will display the sponsored post title prefix.
To do that, you need to add a code snippet to your website. Normally, this is done through your theme’s functions.php file.
However, we don’t recommend editing your theme’s functions.php directly because the smallest error can break your site. Plus, if you update your WordPress theme, all of your customizations will be removed.
Instead, we recommend the WPCode, the easiest and safest way to add code to your WordPress site without having to edit your theme’s functions.php file.

To get started, you need to install and activate the free WPCode plugin. For step by step instructions, see our guide on how to install a WordPress plugin.
Once the plugin is activated, head to Code Snippets » + Add Snippet from your WordPress admin dashboard. Then, hover over the ‘Add Your Custom Code (New Snippet)’ option and click the ‘Use snippet’ button.

After that, simply copy and paste the code snippet into the code box.
add_filter( 'the_title', 'wpb_sponsored' );
function wpb_sponsored( $title ) {
global $post;
$sponsored_text = '<span class="sponsored_text"> Sponsored Post</span> ';
$sponsored = get_post_meta($post->ID, 'sponsored', true);
if( $sponsored == 'true' && in_the_loop() ){
return $sponsored_text.$title;
}
return $title;
}
Don’t forget to choose the ‘PHP Snippet’ option from the Code Type drop-down list on the right side of the screen.

Click the ‘Inactive’ toggle to change it to ‘Active’ and then click the Save Snippet button.
Now WordPress will start displaying the prefix. Try visiting the post you edited earlier, and you will see ‘Sponsored Post’ prefixed to the post title.

We’re making great progress, and with a bit more work we can improve the appearance of the prefix.
If you study the code snippet, then you will notice that we have wrapped the sponsored post text around a CSS class we named ‘sponsored_text’. You can use this CSS class to highlight the text inside the post title.
Here is a little CSS that you can add to your theme.
.sponsored_text {
background: #eeffee;
font-size:small;
text-transform: uppercase;
padding:5px;
}
If you’re new to CSS, then be sure to check out our guide on how to easily add custom CSS to your WordPress site.

The code makes the background of the text green and uppercase and makes the font size small. It also adds a little padding around the highlight. Feel free to modify the CSS to meet your needs.
How to Add a Sponsored Post Suffix with a Code Snippet
You might want to add the words ‘Sponsored Post’ to the end of your post’s title instead of the beginning. You can achieve that by using this code snippet instead.
add_filter( 'the_title', 'wpb_sponsored' );
function wpb_sponsored( $title ) {
global $post;
$sponsored_text = '<span class="sponsored_text"> Sponsored Post</span> ';
$sponsored = get_post_meta($post->ID, 'sponsored', true);
if( $sponsored == 'true' && in_the_loop() ){
return $title.$sponsored_text;
}
return $title;
}

When you study the code you’ll notice that we’ve made just two changes.
We added a single letter space before the sponsored text, and then we switched the order to display $title
first.

We hope this article helped you to learn how to add a sponsored post prefix to post titles in WordPress. You might also like to learn the right way to create an email newsletter or see our comparison of the best email marketing services.
If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.
kenn says
how can i created sponsored products not post. i want my sellers to be able to create sponsored products
WPBeginner Support says
You would want to check with the support for your ecommerce plugin for if it has a sponsored product option
Admin
vo thang says
I’ve done it,that’s Ok.But,Title post is appear in home page without sponsored text.
How can I make it appear in Home page ?
Thank you so much.
Angela Scott says
Is there a way to add an image in place of the text, please?
Soibibo says
Hi, I’m new to WordPress and talking about pasting codes to function.php file almost made me loose my site. please where exactly can I post this code on the function.php folder? I have zero knowledge of codes.
WPBeginner Support says
Please take a look at our guide on pasting snippets from web into WordPress.
Admin
Ranish Malhan says
Hi,
I have created a custom meta feild for my custom post type which is a check box.
So can u please tell how to display posts by checking whether that checkbox is checked or not?
WPBeginner Staff says
Yes.
VIAINA says
Hi, does “sponsored post” is also shown in the RSS feed?
Thanks.
clreed87 says
Thanks for the great tip! Will filtering on the_title() also be reflected in the RSS feeds for sponsored posts or just on the blog posts on the site?
Caroline says
Great article. Works like a charm. But I cannot seem to make the custom field be saved so I can pick it from the dropdown box for a next post.
Any idea what I’m doing wrong?