Let’s say you wanna prepend the word “Special: ” to every stick post’s title you can place the following in your functions.php
:
add_filter( 'the_title', 'sticky_title' );
function sticky_title( $title ) {
// Check if a post is set to sticky.
if ( is_sticky() ) {
// Prepend "Special: " to post title.
return 'Special: ' . $title;
}
return $title;
}
I want’s to design this ‘special : ‘ word into different color and i
wants this will appear my every sticky post’s left corner… How can i
do this?
You could do that with just CSS using post_class()
or by hooking into post_class()
. Normally the <article>
tag already comes with a .sticky
class.
If you use a custom theme you can simply have a look at the Twenty Nineteen theme’s template-parts/content/content.php
and use that approach yourself in your home.php
or in whatever template you need it:
if ( is_sticky() && is_home() && ! is_paged() ) { printf( '<span class="sticky-post">%s</span>', _x( 'Featured', 'post', 'twentynineteen' ) ); }