I’m working on a custom theme for WordPress and have what is probably the silliest issue with a comma! I’m using the following code to present entry-meta:
<?php
printf( __( '<span class="meta-prep meta-prep-author screenreader">Posted on </span><a href="%1$s" rel="bookmark"><time class="entry-date" datetime="%2$s" pubdate>%3$s</time></a> <span class="meta-sep"> by </span> <span class="author vcard"><a class="url fn n" href="%4$s" title="%5$s">%6$s, %7$s</a></span>', 'ngngcustom' ),
get_permalink(),
get_the_date( 'c' ),
get_the_date(),
get_author_posts_url( get_the_author_meta( 'ID' ) ),
sprintf( esc_attr__( 'View all posts by %s', 'ngngcustom' ), get_the_author() ),
get_the_author(),
get_the_author_meta('user_title')
);
?>
The problem is that not all users will have a title. How do I get rid of the hanging comma (between %6$s and %7$s) in those instances? Please realize I don’t know php. I just copy / paste and tweak it a bit. So I really need a clear solution.
Try this. Get rid of the comma in your
printfand add this code: