Trusted WordPress tutorials, when you need them most.
Beginner’s Guide to WordPress
WPB Cup
25 Million+
Websites using our plugins
16+
Years of WordPress experience
3000+
WordPress tutorials
by experts

How to Add Sponsored Post Prefix to Post Title in WordPress

If you post sponsored content, it’s important to follow regulations by clearly labeling those posts. One easy way to do this is by adding a ‘Sponsored Post’ prefix to your titles.

While we don’t do sponsored posts on WPBeginner, we have a similar feature.

We believe it’s important to disclose that our content is reader-supported. So, if you read our blog posts, you’ll see this disclosure at the end of each post. This helps us maintain transparency.

Manually adding this snippet can be tedious, which is why we automate the process.

In this article, we will show you how to automatically add a “Sponsored Post” prefix to your post titles in WordPress.

How to Add Sponsored Post Prefix to Post Title 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.

Preview of Sponsored Post Preview with Custom CSS

We’ll show you how to do exactly that in this guide. It’s easier than you may think. You can do it through the block editor and then adding a custom code snippet. This may seem intimidating to beginners, but we’ll walk you through every step using the free WPCode plugin.

With that in mind, here’s a quick look at 3 methods you can use to add a ‘Sponsored Post’ prefix to your post titles in WordPress:

Ready? Let’s get started!

Method 1: How to Add a Sponsored Post Custom Field to Your Post

You can 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.

Block Editor Preferences

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, you’ll want to click on the ‘Enable & Reload’ button to reload the post editor.

Display Custom Fields in Block Editor

If you are still using the old WordPress classic editor, then you can click the ‘Screen Options’ button at the top right corner of your screen.

This will open a menu where you need to check the box next to the ‘Custom Fields’ options.

Screen Options in Classic Editor

The post editor will then reload.

When you scroll below the content editor you’ll be able to see the custom fields panel.

Add Custom Field

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.’

Adding a New Custom Field

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.

Custom Field Drop Down Menu

Method 2: 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 using WPCode, the easiest and safest way to add code to your WordPress site without having to edit your theme’s functions.php file.

WPCode's homepage

To get started, you need to install and activate the free WPCode plugin. For step-by-step instructions, you can see our guide on how to install a WordPress plugin.

Once the plugin is activated, let’s head to Code Snippets » +Add Snippet from your WordPress admin dashboard. Then, you’ll want to hover over the ‘Add Your Custom Code (New Snippet)’ option and click the ‘Use snippet’ button.

Add your new custom code snippet in WPCode

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.

Add Code Snippet to Display Sponsored Post Prefix in WPCode

Then, you’ll need to click the ‘Inactive’ toggle to change it to ‘Active’ and the ‘Save Snippet’ button.

Now, WordPress will start displaying the prefix. You can try visiting the post you edited earlier, and you will see ‘Sponsored Post’ prefixed to the post title.

Preview of Sponsored Post Prefix

With a bit more work, you 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.

Preview of Sponsored Post Preview with Custom CSS

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.

Method 3: 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;
}

Here’s what it looks like on WPCode’s ‘Code Preview:’

Add Custom Code Snippet for Sponsored Post Suffix in WPCode

When you study the code, you’ll notice that there are just 2 changes.

We added a single letter space before the sponsored text so that it wouldn’t touch the actual post title, and then we switched the order to display $title first.

That’s it!

Here’s what it might look like on the live blog post:

Preview of Sponsored Post Suffix with Custom CSS

Bonus Tip: How to Write an Affiliate Product Review

If you already use sponsored posts to make money blogging, you may be looking for other ways to monetize your site.

Affiliate marketing can be a great way to earn passive income. By writing engaging product reviews, you can build trust with your audience and encourage them to make purchases.

Here are some tips to help your affiliate product reviews stand out:

  • Use Facts and Share Your Experience: Start with product details like specifications and then share your personal experience to add a genuine touch.
  • Search for Customer Reviews: Look at feedback from other users to gain insights and learn about common issues. This helps you provide a well-rounded review.
  • Create Transparency: Always include an affiliate disclosure at the top or bottom of your post. Be honest about the product’s pros and cons to set realistic expectations.
  • Identify Needs and Provide Solutions: Know your audience’s challenges and recommend products that can help them. This makes your reviews more relevant.
  • Use High-Quality Images: Include clear images to showcase the product. Just make sure to optimize your images so they don’t slow down your site.
  • Focus on SEO: Optimize your reviews with relevant keywords, especially in the first 150 words. This will help your content rank higher in search results.
  • Create Attractive Affiliate Links: Use a plugin like ThirstyAffiliates to shorten and customize your affiliate links, making them look cleaner and more trustworthy.

For more details, you can check out our article on how to write an affiliate product review.

We hope this article helped you learn how to add a sponsored post prefix to post titles in WordPress. Next, you might also like to learn how to insert ads within your post content or our expert picks of the best WordPress ad management plugins and solutions.

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.

Disclosure: Our content is reader-supported. This means if you click on some of our links, then we may earn a commission. See how WPBeginner is funded, why it matters, and how you can support us. Here's our editorial process.

Editorial Staff

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi with over 16 years of experience in WordPress, Web Hosting, eCommerce, SEO, and Marketing. Started in 2009, WPBeginner is now the largest free WordPress resource site in the industry and is often referred to as the Wikipedia for WordPress.

The Ultimate WordPress Toolkit

Get FREE access to our toolkit - a collection of WordPress related products and resources that every professional should have!

Reader Interactions

12 CommentsLeave a Reply

  1. Syed Balkhi

    Hey WPBeginner readers,
    Did you know you can win exciting prizes by commenting on WPBeginner?
    Every month, our top blog commenters will win HUGE rewards, including premium WordPress plugin licenses and cash prizes.
    You can get more details about the contest from here.
    Start sharing your thoughts below to stand a chance to win!

  2. kenn

    how can i created sponsored products not post. i want my sellers to be able to create sponsored products

    • WPBeginner Support

      You would want to check with the support for your ecommerce plugin for if it has a sponsored product option

      Admin

  3. vo thang

    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.

  4. Angela Scott

    Is there a way to add an image in place of the text, please?

  5. Soibibo

    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.

  6. Ranish Malhan

    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?

  7. VIAINA

    Hi, does “sponsored post” is also shown in the RSS feed?
    Thanks.

  8. clreed87

    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?

  9. Caroline

    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?

Leave A Reply

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.