Archived topic
Show current date in header
13 replies · Started by Leon on July 10, 2020
I'd like to show the current date in the header in the new (GeneratePress) version of my site. In the present (custom-made) theme that is done by adding a little code to header.php. How can I create in in GeneratePress?
Thanks, Leon
Hi there,
you can add this PHP Snippet to your site:
<?php echo date('l jS F Y'); ?>
using a Hook Element:
https://docs.generatepress.com/article/hooks-element-overview/
Or Leo provides some code here to create your own shortcode that you can add to widet areas as well as Hooks:
https://generatepress.com/forums/topic/changing-the-copyright-message-full-date/#post-617442
Hi,
I finally had the time to give this a try. I made a hook element "after_logo":
opening div
<?php echo date(‘l jS F Y’); ?>
end div
and checked "Execute PHP"
As a result I got a message "critical fault in my website" and was told to check "problem solving in WordPress"
In Dutch:
Er heeft zich een kritische fout voorgedaan op je website.
Lees meer over probleemoplossing in WordPress.
If I uncheck "Execute PHP" I don't see anything. If I then replace the php with a few words, they show up right.
What do I do wrong here?
Thanks, Leon
I just tried adding this:
<div class="header-date">
<?php echo date('l jS F Y'); ?>
</div>
Without any issues:
https://www.screencast.com/t/P1SaO5HaWvg
Can you try again?
Hi Leo,
I don't understand why, but now it works indeed.

In my css I added:
.header-date {
color: #000000;
text-align: right;
float: right;
margin-top: 104px;
}
That works fine, when the window is wider than the header image. In tablet view and smaller, the date appears under the logo (including that 104px).

In those cases I'd like the date to be just below the logo. Is there an easy way to achieve that?
Thanks, Leon
Hi there,
can you remove any CSS related to the Dates positioning - there is a lot of it and i am sure we can do something simpler.
Sure.
This is the css left:
.header-date {
color: #000000;
text-align: right;
}
And this is the hook (after_logo, √ execute PHP)
Leon (do you see the div-tags? They seem to vanish in the forum-post.)
I am seeing lots of CSS related to the date - using vaious CSS selectors such as thes:
#wrapper #header div.head-wrap #headerkoptekst
I think you are looking at the wrong site; #headerkoptekst for instance is used in the present site with a custom theme.
In mbo-today.nl/test I only use the css that came with Wordpress and Generatepress. I provided the login data earlier, but I can of course send them again.
If you can send the login over again that would be appreciated.
Sure, I did send the login by the mail on the contact page.
Leon
Try this CSS instead:
/* relative position header */
.inside-header {
position: relative;
}
/* position date relative to header */
.header-date {
color: #000;
text-align: right;
pointer-events: none;
position: absolute;
bottom: 45px;
right: 20px;
}
/* reduce date font size on small devices */
@media(max-width: 420px) {
.header-date {
font-size: 12px !important;
}
}
Hi David,
Thanks again. This works perfect.
Leon
Glad to hear that