Site logo

Archived topic

Disable Author / Date Link on Entry Meta in Single Post / Archive Pages

7 replies · Started by Jasmina on February 13, 2019

Viewing posts 1–8 of 8

Hi,

I tried to disable the author link and the date / modified date on single post and archives. (not the text, just want to disable links)

I am using this code to style the meta post data: https://docs.generatepress.com/article/entry-meta-style/

1. problem: the arrangement of the post meta on single posts is different to the post meta on archives.
arrangement on single post: author | modified date | comment count
arrangement on archive pages: author | comment count | modified date > Like here:

How can I arrange it in the same way on every single post AND archive pages?

2. problem: when I additionally use your snippets for disbaling the author link and date link, the link is still clickable or a second line with a date is added.

how can I solve this problem?

Thanks
Jasmina

Hi there,

So the main difference is the comment count? Would you like to add it to the single posts, or remove it from the archives?

You'll need to disable the links inside the same function you're using to re-order them. Any chance you can share your function and I can tweak it for you?

Let me know :)

Hi Tom,

I reordered the meta data with these two snippets:

add_filter( 'generate_post_author', '__return_false' );
add_filter( 'generate_show_comments', '__return_false' );
add_filter( 'generate_post_date_output', 'tu_fancy_byline' );
function tu_fancy_byline( $date ) {
	printf( ' <span class="byline">%1$s</span>',
		sprintf( '<span class="author vcard" itemtype="http://schema.org/Person" itemscope="itemscope" itemprop="author">%4$s<a href="%1$s" title="%2$s" rel="author"><span class="author-name" itemprop="name">%3$s</span></a></span>',
			esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
			esc_attr( sprintf( __( 'View all posts by %s', 'generatepress' ), get_the_author() ) ),
			esc_html( get_the_author() ),
			get_avatar( get_the_author_meta( 'ID' ) )
		)
	);

	if ( ! is_single() && ! post_password_required() && ( comments_open() || get_comments_number() ) ) {
		echo '<span class="comments-link">';
			comments_popup_link( __( 'Leave a comment', 'generatepress' ), __( '1 Comment', 'generatepress' ), __( '% Comments', 'generatepress' ) );
		echo '</span>';
	}

	echo $date;
}

Second Snippet:

add_filter( 'generate_post_date_output', 'lh_single_comments_link' );
function lh_single_comments_link( $date ) {
  
    echo $date;

	if ( is_single() && ! post_password_required() && ( comments_open() || get_comments_number() ) ) {
		echo '<span class="comments-link">';
			comments_popup_link( __( 'Leave a comment', 'generatepress' ), __( '1 Comment', 'generatepress' ), __( '% Comments', 'generatepress' ) );
		echo '</span>';
	}	
}

Now my target is to disable the author-link and the date-link in the meta data - shown in single post and on archive pages.

Thanks a lot
Jasmina

Hi there,

Try this as your function (and remove the second one):

add_filter( 'generate_post_author', '__return_false' );
add_filter( 'generate_show_comments', '__return_false' );
add_filter( 'generate_post_date_output', 'tu_fancy_byline', 10, 2 );
function tu_fancy_byline( $date, $time_string ) {
    printf( ' <span class="byline">%1$s</span>',
        sprintf( '<span class="author vcard" itemtype="http://schema.org/Person" itemscope="itemscope" itemprop="author">%4$s<span class="author-name" itemprop="name">%3$s</span></span>',
            esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
            esc_attr( sprintf( __( 'View all posts by %s', 'generatepress' ), get_the_author() ) ),
            esc_html( get_the_author() ),
            get_avatar( get_the_author_meta( 'ID' ) )
        )
    );

    if ( ! post_password_required() && ( comments_open() || get_comments_number() ) ) {
        echo '<span class="comments-link">';
            comments_popup_link( __( 'Leave a comment', 'generatepress' ), __( '1 Comment', 'generatepress' ), __( '% Comments', 'generatepress' ) );
        echo '</span>';
    }

    printf( '<span class="posted-on">%s</span>',
        $time_string
    );
}

Thanks a lot, Tom! :) Copied your function an removed the 2nd one.

Now I´m just missing the "Comments"-Part in meta data on single posts. Take a look - there are just author + date > example https://www.seniorpfoten.de/nasenbluten-hund/

Great! :-) It works

Excellent support!
Tanks a lot

You're welcome :)

This archived topic is closed to new replies.