Site logo

Archived topic

Hi, I want to show "Author/updated date

46 replies · Started by Rahul on February 1, 2021

Viewing posts 31–45 of 47

Could you disable your cache plugin and clear all cache first?

Hi, Ying" I disabled my all plugins and cookies, but it's not changing the date after the update. If you want I can add you to my site, I hope then you can investigate more.

Hello Mr. Elvin Please check the details. And take a look closer and let me know if you get more problems.

Hi,

I've checked your site and it's as I've suspected.

You've mentioned installing Code Snippets plugin and applying the PHP snippet here:
https://generatepress.com/forums/topic/hi-i-want-to-show-author-updated-date/#post-1645891

But when I checked your site, I didn't see any Code Snippets plugin or Child theme that possibly let's you add the PHP snippet David suggested here - https://generatepress.com/forums/topic/hi-i-want-to-show-author-updated-date/#post-1645708

Note: The PHP snippet has to be implemented if you want to make any changes on how the post's dates are displayed.

Clarification: Do you want do display both modified date and posted date or do you want to display modified date if it exist, else display post date? Let us know.

I have installed the "code snippets" plugin and applied such PHP but I found some problem then again I delete it. And I don't want to apply anything new.

Now everything is good to see. But the only problem if I update any post then it shows only old date not updated.

Already I said I updated this post on February 07, 2021, , but it shows January 27, 2021. I think it should change the date automatically. If you can fix it, then it would better for me.

I have installed the “code snippets” plugin and applied such PHP but I found some problem then again I delete it. And I don’t want to apply anything new.

I'm afraid we'll need the Code Snippets plugin or a Child theme's functions.php to implement the changes as the these things are the means for implementing the change you want to achieve. We can't help you out unless either of the two are implemented as we really need a means to run PHP snippets to apply changes to the theme's default functions.

Ok, Install the "code snippets" plugin. And move further

Ok, Install the “code snippets” plugin. And move further

It’s against our policy to make changes such as installation of child theme or any plugins to your site.

Can you install it and add this PHP snippet in?

function db_modified_time_stamp( $output, $time_string ) {
    $time_string = '<time class="entry-date published" datetime="%1$s" itemprop="datePublished">Posted on %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;
	}

    // Check modified date is newer thant published

    $updated_time = get_the_modified_time( 'U' );
    $published_time = get_the_time( 'U' ) + 86400;

    // If modified date exists then ouput both time strings with modified date
    
    if ( $updated_time > $published_time ) {
        $time_string = '<time class="entry-date published" datetime="%1$s" itemprop="datePublished" style="display: none;">Posted on %2$s</time>
        <time class="entry-date updated-date" datetime="%3$s" itemprop="dateModified" style="display:inline;">Updated on %4$s</time>';
    }

    	$time_string = sprintf( $time_string,
		esc_attr( get_the_date( 'c' ) ),
		esc_html( get_the_date( 'F j, Y' ) ),
		esc_attr( get_the_modified_date( 'c' ) ),
		esc_html( get_the_modified_date( 'F j, Y' ) )
	);

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

add_filter( 'generate_post_date_output', db_modified_time_stamp, 20, 2);

Here's how it should be: https://share.getcloudapp.com/WnuBJBYR

Here's an actual demo site of it working: Code Snippet demo

On the demo site, you can see that some posts have "Updated on" and some have "Posted on". These are applied by the snippet.

Hi, it's working. I'm trying to maintain everything for google "E.A.T"

However, please see the link and look at their post thumbnail image where you'll see two authors. And if you just hover your mouse on their name you'll see some information about them. Do you know how can I apply it?

Use this PHP snippet to add the author image:

add_filter( 'generate_post_author_output', function() {
    return sprintf( ' <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' ) )
        )
    );
} );

You then add this CSS so the image is styled look rounded:

.byline img {
    width: 25px;
    height: 25px;
    border-radius: 50%;
    position: relative;
    vertical-align: middle;
    margin: 0 10px 0 0;
}

And if you just hover your mouse on their name you’ll see some information about them. Do you know how can I apply it?

That reference site's author links may be using a plugin or customized with scripts. I'm afraid this kind of customization is outside of our scope of support.

Yes, it's working. Thank's a lot! Finally, I want to make them like it instead of the current style.

EXAMPLE: By tahsin / February 10, 2021

Or you can check my another site, where I used Astra pro.

Add this PHP snippet to sort which appears first.

add_filter( 'generate_header_entry_meta_items', function() {
    return array(
        'author',
        'date'
    );
} );

As for adding / before the date, go and edit the PHP snippet that displays the modified date and replace the texts Posted on and Updated on with /.

Hi, Mr. Elvin Now solved all problems. But I request you to check my site's overall codes so that google can easily read my website. If you found any error please tell me, and thanks for your all help.

NOTE: I have updated the code I attached, please check if I made a mistake

But I request you to check my site’s overall codes so that google can easily read my website.

I'm afraid this kind of service is outside of our scope of support. Consider hiring an SEO expert with developer experience as this has to be done by one to get the results you want to achieve.

I've skimmed through the code and I'm not sure it's a good idea to completely remove the <time> tags and their attributes. While i understand that this is your attempt to hide the date from Google's crawler bots, I'm not exactly sure if it's effective.

As for what's effecting, it's best to consult an SEO expert. :)

This archived topic is closed to new replies.