How to Add Sponsored Post Prefix to Post Title in WordPress657

Author: InfoBeep - December 11, 2017 | subject to copyright

If you have been using blog for a long time and you think its time to for you to generate a income from it. Sponsoring products and services can be a way to generate a income for you. So if you want to add sponsored post in you blog, here is steps, you may follow it:

  • First of all, create a new post or go to the post where you want to add sponsored post.
  • Now, tick the Custom Fields option. If you didn’t find it, click on Screen Options, you will see Custom Fields option over there. Demo image is shown below:

custom-fields

  • Now, scroll down, you will see a Custom Fields meta box fill it as shown in the picture.

custom-fields-one

  • After you are done, save your post.
  • Now you need to paste the following code in you function.php file or site-specific plugin.
add_filter( 'the_title', 'wpb_sponsored');

functionwpb_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;

}