Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator keesiemeijer

    (@keesiemeijer)

    Try it with this in your theme’s functions.php:

    add_filter( 'widget_display_callback', 'categoryposts_custom_title', 10, 3 );
    
    function categoryposts_custom_title( $instance, $widget, $args ) {
    
    	if ( $widget->id_base == 'categoryposts' ) {
    		add_filter( 'the_title', 'add_new_to_title', 10, 2 );
    	}
    	return $instance;
    }
    
    function add_new_to_title( $title, $id ) {
    
    	$post = get_post( $id );
    
    	if ( $post ) {
    		if ( strtotime( $post->post_date ) > strtotime( '-30 days' ) ) {
    			$title .= " New!";
    		}
    	}
    
    	return $title;
    }

    btw:
    consider creating a child theme instead of editing your theme directly – if you upgrade the theme all your modifications will be lost.

    Thread Starter Nientje07

    (@nientje07)

    Hello,

    thank you very much for the reply! It worked perfectly!

    (P.s.: I already work with a childtheme, so that is no problem)

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Add 'New!' After Post title’ is closed to new replies.