• I’m trying to add the last updated date to the post metas, I’m aware of the option in the Customizer but it is a bit unwieldy and I’d rather not have it on the post lists as well.

    So far I’ve managed to do it properly with the following code using the tc_author_meta filter:

    add_filter( 'tc_author_meta' , 'add_the_updated_date');
    function add_the_updated_date() {
        if (is_singular('post')) {
            return sprintf( '<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s" rel="author">%3$s</a></span>(last updated on" <time class="entry-date" datetime="%4$s">%5$s</time>)' ,
                esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
                esc_attr( sprintf( __( 'View all posts by %s' , 'customizr' ), get_the_author() ) ),
                get_the_author(),
                esc_attr( get_the_modified_date('c') ),
                get_the_modified_date('j M Y')
             );
        }
        else {
            return sprintf( '<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s" rel="author">%3$s</a></span>' ,
                esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
                esc_attr( sprintf( __( 'View all posts by %s' , 'customizr' ), get_the_author() ) ),
                get_the_author()
             );
        }
    }

    [actual code is more complicated but I stripped it down for simplicity]
    The above works fine and is perfect (except that the added code is within the <span class="by-author"> tag). However, I’m trying to understand why the same editing technique doesn’t work when using the tc_post_metas filter instead. For example, the following code:

    add_filter( 'tc_post_metas' , 'add_the_updated_date');
    function add_the_updated_date() {
    if (is_singular('post') ) {
               return sprintf( '<div class="entry-meta">%1$s(last updated on" <time class="entry-date" datetime="%2$s">%3$s</time>)</div>',
                  apply_filters( 'tc_meta_utility_text', $_html , $_args ),
                  esc_attr( get_the_modified_date('c') ),
          	      get_the_modified_date('j M Y')
                );
    	} else {
               return sprintf( '<div class="entry-meta">%s</div>',
                  apply_filters( 'tc_meta_utility_text', $_html , $_args )
                );
    }
    }

    … doesn’t work as it does not print the %1$s. This is more of an academic question and I was just wondering why the editing worked with one filter but not the other.

    Thanks for your time!

  • The topic ‘Question about tc_post_metas filter’ is closed to new replies.