Archived topic
Displaying Posted (and updated) Date on pages
25 replies · Started by culpable on December 28, 2018
Hi,
I feel silly asking this – but which setting enables showing the "Published on" date for a wordpress page?
I remember it always being on by default, but for some reason this time it is not showing.
(I also want to show a "Last Updated: " date – I presume this is still the best way to do it?)
Thank you in advance for your help during this holiday period
Hi there,
If you want to show both dates, remove this CSS from the documentation page:
.posted-on .updated + .entry-date {
display: none;
}
Let me know if this makes sense :)
Hi Leo,
That does make sense. But I'm wondering why neither date is appearing right now, even though I haven't added any CSS yet? Shouldn't the "Published Date" be showing? Is this a setting somewhere that I'm missing?
Is it enabled here?
https://docs.generatepress.com/article/blog-content-layout/#single
Yeah it is... but it’s not showing up.
There doesn’t seem to be an "entry-meta" div: https://imgur.com/a/GGcQSIO
(note that the published + updated date is showing correctly when I use WPSP plugin to display the post on another page)
That's very weird.
Any custom functions added?
Nothing....
It’s not a child theme. And I checked the Elements tab – no custom code running on these pages.
You can see here https://imgur.com/a/DwjnFrc that they are showing with WPSP.
I'm not sure what to do – should I maybe double check the code in the Editor?
WPSP is separated from GP so that doesn't tell us too much.
Can you try #1 here to eliminate any plugin conflicts first?
https://docs.generatepress.com/article/debugging-tips/
Ah okay, no worries. Just wanted to show that the dates actually existed.
Just to confirm before I deactivate the plugins – Will the settings all remain?
I currently have 50+ Posts under the WPSP plugin... so I'd be quite upset if that were lost :'(
Yes the settings should be fine :)
It was working before and now it's not so something had to change.
Deactivated it all except for GP Premium – still not showing :|
Just to confirm, are you wanting to display dates on pages as well as blog posts?
It’s a wordpress page (which I needed to make clearer in the OP, sorry).
Your message reminded me of this code I used in my other website to display the date:
add_action( 'generate_after_entry_header', 'tu_page_meta' );
function tu_page_meta() {
if ( 'page' == get_post_type() ) : ?>
<div class="entry-meta">
<?php generate_posted_on(); ?>
</div>
<?php endif;
}
Can I ask a few ignorant questions related to this:
#1 Should I add this via Generatepress -> Elements -> Hook + "Execute PHP" or via a code snippet?
#2 What is the difference between using a Hook that executes PHP vs. using a code snippet or using a child theme to insert the PHP?
#3 I was currently using this plugin (https://wordpress.org/plugins/insert-php/). I see in your "Adding PHP" post you recommend this plugin (https://en-ca.wordpress.org/plugins/code-snippets/). Is there any performance-related reasons as to why this is? (I don’t want to unnecessarily slow down my website)
#4 How can I adjust the code to also show the "Last Updated" date? Will it be there automatically, just hidden via CSS? So I'd just use this: https://docs.generatepress.com/article/show-the-updated-post-date/ to show it?
Thank you very much for your help :)
Ahh sorry for the whole time I thought we are talking about single posts.
Yes that code is required to display date on pages.
#1 The code in that format would need to be added using Code Snippets or function.php of your child theme.
#2 Sometimes the code won't work in hook. In this case you can also use Hook Element but the code would be like this:
<?php if ( 'page' == get_post_type() ) : ?>
<div class="entry-meta">
<?php generate_posted_on(); ?>
</div>
<?php endif; ?>
#3 Code Snippet is the one suggested. Should have minimal impact on your site.
#4 The CSS in the doc page should still work.
No worries Leo – I should have made it clearer.
In response to your comments:
#1 Okay, no problem.
#2 Strange... I still don’t understand the difference. Will need to read into it more. Is there a performance difference – i.e. should I implement it as a hook, or as a snippet?
#3 Okay. So should I convert all my PHP Snippets -> Code snippets then? Are you implying that PHP snippets is not as fast?
#4 Awesome.
Thank you for your help Leo! :)