How To Add Sponsored Post Prefixes To Post Titles In WordPress

preview_player
Показать описание
This video is about how to add sponsored post prefixes to post titles in wordpress. If have post-sponsored content on your website, you can differentiate them from your other content by adding a sponsored post prefix on the post.

0:12 - Adding Sponsored post prefix
2:20 - Adding some Custom CSS
3:13 - Adding Sponsored post suffix

▼ More Tutorials By Fix Runner ▼
👉 How To Remove Query Strings From Static Resources in WordPress ►

▼ More Playlists By Fix Runner ▼

Fixrunner offers professional WordPress help and WP support by our experts. We take care of all the backups, updates, security, speed optimization, and much more. Furthermore, our fast 1-time WordPress fix services for any WP emergency. Additionally, WP hosting service and any future development work you may need.
Рекомендации по теме
Комментарии
Автор

★ Code used in video ►
prefix –
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;
}

CSS –
.sponsored_text {
background: #eeffee;
font-size:small;
text-transform: uppercase;
padding:5px;
}

Suffix –

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

fixrunnercom
Автор

Great video, But what if I want to add prefix whitout any custom field?
Is there any way to update post title in database with our custom suffix text.... (Suffix should be added only when user saves the post first time)

shaharyaransari