0

I have 3 different custom post types (news, job, result ,) When I post something new under any of them, I want "new" label or gif for a limited time in title . Am already try that one which am found in old ans... But not working for me

add_filter( 'post_class', function( $classes ) 
{
    if ( is_singular() )
        return $classes;

    // now minus last mod time in seconds
    $diff = time() - mysql2date( 'U', $post->post_date );

    if ( DAY_IN_SECONDS <= $diff ) $classes[] = 'new-post';
        return $classes;
});

Css

.new-post {
    padding-left: 20px;
    background-image: url(new.png) left top no-repeat;
}
  • Welcome to WPSE, what did you try already, can we have some code with which we may or may not be able to help. – Charles Dec 13 '19 at 19:10
  • I try one old answer from here . But that one not work for me am simply want to add 'new' label after custom post title. I don't know how to do that . Am beginner in php – Ankit Jain Dec 13 '19 at 19:34
  • Am tried that one – Ankit Jain Dec 13 '19 at 19:38
  • add_filter( 'post_class', function( $classes ) { if ( is_singular() ) return $classes; // now minus last mod time in seconds $diff = time() - mysql2date( 'U', $post->post_date ); if ( DAY_IN_SECONDS <= $diff ) $classes[] = 'new-post'; return $classes; }); – Ankit Jain Dec 13 '19 at 19:38
  • The post_class hook applies to the currently viewed item. So, it would affect single posts. But your first conditional says that if the current item is singular (which it always is because of the hook you've chosen) it should simply return the existing classes without modifying them. Your first step is to identify where you want the new label to appear, and then find the right hook or template file to target that location. – WebElaine Dec 13 '19 at 19:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.