[Resolved] showing comments link in meta

Home Forums Support [Resolved] showing comments link in meta

Home Forums Support showing comments link in meta

Viewing 15 posts - 16 through 30 (of 43 total)
  • Author
    Posts
  • #676806
    Tom
    Lead Developer
    Lead Developer

    Sorry for not getting back to you sooner!

    Can you share the functions you’re currently using along with any CSS (relating to this topic)?

    Just need to get an idea of what could be conflicting.

    #676950
    dassana

    the function which i am using is with this css code.

    #677270
    Tom
    Lead Developer
    Lead Developer

    This function is causing the conflict:

    if ( ! function_exists( 'generate_posted_on' ) ) :
    /**
     * Prints HTML with meta information for the current post-date/time and author.
     */
    function generate_posted_on() {
    
    	if ( 'post' !== get_post_type() ) 
    		return;
    		
    	$time_string = '<time class="entry-date published" datetime="%1$s" itemprop="datePublished">%2$s</time>';
    	if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) )
    		$time_string .= '<time class="updated" datetime="%3$s" itemprop="dateModified">%4$s</time>';
    
    	$time_string = sprintf( $time_string,
    		esc_attr( get_the_date( 'c' ) ),
    		esc_html( get_the_date() ),
    		esc_attr( get_the_modified_date( 'c' ) ),
    		esc_html( get_the_modified_date() )
    	);
    
    	printf( __( '<span class="posted-on">%1$s</span> <span class="byline">%2$s</span>', 'generatepress' ),
    		sprintf( '%1$s',
    			$time_string
    		),
    		sprintf( '<span class="author vcard" itemtype="http://schema.org/Person" itemscope="itemscope" itemprop="author">%1$s <span class="author-name" itemprop="name">%2$s</span></span>',
    			__( 'by','generatepress'),
    			esc_html( get_the_author() )
    		)
    	);
    }
    endif;

    If you remove it, does the function Leo provided work?

    #677292
    dassana

    thanks a lot tom. yes now it does work.

    #677336
    Tom
    Lead Developer
    Lead Developer

    Can you turn off your caching plugin? I’m still seeing the old way you had set up.

    So just to confirm, you want:

    1. Only the modified date to show up in the source if it’s been modified, otherwise you want the published date to show up. Only 1 of the 2 should appear in the source at a time.

    2. The date and author shouldn’t have links.

    3. The comment count should be appended at the end of the line.

    Correct?

    #677348
    dassana

    i have flushed the cache of this link from the server. can you refresh it and check again.

    #677352
    dassana

    please do refresh if you do not see the changes.

    #677475
    Tom
    Lead Developer
    Lead Developer

    You have two different posted-on elements for some reason. Are you sure there aren’t any other functions hiding somewhere?

    If you want the structure to look like this: Date by author | comments

    You can do this:

    add_filter( 'generate_post_date_output','tu_remove_date_link', 10, 2 );
    function tu_remove_date_link( $output, $time_string ) {
    	printf( '<span class="posted-on">%s</span>',
    		$time_string
    	);
    }
    
    add_filter( 'generate_post_author_output','tu_no_author_link' );
    function tu_no_author_link() {
        printf( ' <span class="byline">%1$s</span>',
            sprintf( '<span class="author vcard" itemtype="http://schema.org/Person" itemscope="itemscope" itemprop="author">%1$s <span class="fn n author-name" itemprop="name">%4$s</span></span>',
                __( 'by','generatepress'),
                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() )
            )
        );
    
        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>';
        }
    }

    I don’t understand this part:

    actually both should appear in the source code, but in the creative work and hatom fields, only the updated date should appear

    Where would the published date appear in this case?

    #677754
    dassana

    hi tom

    i added the code you have given and its looking good now.

    #677993
    Tom
    Lead Developer
    Lead Developer

    To show the updated date to humans, this should be all that’s necessary: https://docs.generatepress.com/article/show-the-updated-post-date/

    We can try removing the structured data from the published date if a modified date exists by replacing this function:

    add_filter( 'generate_post_date_output', 'tu_remove_date_link', 10, 2 );
    function tu_remove_date_link( $output, $time_string ) {
        printf( '<span class="posted-on">%s</span>',
            $time_string
        );
    }

    With this:

    add_filter( 'generate_post_date_output', function( $output, $time_string ) {
    	$time_string = '<time class="entry-date published" datetime="%1$s" itemprop="datePublished">%2$s</time>';
    	
    	if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
    		$time_string = '<time class="updated" datetime="%3$s" itemprop="dateModified">%4$s</time><time class="entry-date published">%2$s</time>';
    	}
    	
    	$time_string = sprintf( $time_string,
    		esc_attr( get_the_date( 'c' ) ),
    		esc_html( get_the_date() ),
    		esc_attr( get_the_modified_date( 'c' ) ),
    		esc_html( get_the_modified_date() )
    	);
    
    	return sprintf( '<span class="posted-on">%s</span>', // WPCS: XSS ok, sanitization ok.
    		$time_string
    	);
    }, 10, 2 );
    #678009
    dassana

    thanks a ton tom. you have really gone out of the way to help me out. wish you all the best and great success. i do have some issues with styling, but that for later. i will try on my own and if i am not able to do, then i will post in forum. thanks again.

    #678014
    dassana

    one issue here. the updated date is getting linked. how i do get rid of the link from the date.

    #678229
    Tom
    Lead Developer
    Lead Developer

    There must be another function conflicting. The function we’re using above completely removes the link. Is there another post date filter in there?

    #678370
    dassana

    thanks tom. there was a function which you had given earlier. i have removed it.

    #678372
    dassana

    for this url i have flushed the cache.

Viewing 15 posts - 16 through 30 (of 43 total)
  • You must be logged in to reply to this topic.