- This topic has 25 replies, 3 voices, and was last updated 6 years, 8 months ago by
Leo.
-
AuthorPosts
-
December 30, 2018 at 4:05 pm #769502
Leo
StaffCustomer Support#2/#3 There are two ways to use hooks, one is to use Hook Element and the other is to use functions:
https://docs.generatepress.com/article/using-hooks/It’s generally easier to use hook element if you aren’t comfortable with coding as you can set it to show on certain pages without using PHP conditional tags.
The difference in performance should be minimal. Code is code no matter how you add them ๐
December 30, 2018 at 7:54 pm #769576culpable
Thanks Leo, that helps a lot. On your point about the hook element’s ability to show on certain pages without code โ does that mean that if I use the display rule “All Pages”, then I can omit the “php if” part of the below:
<?php if ( 'page' == get_post_type() ) : ?> <div class="entry-meta"> <?php generate_posted_on(); ?> </div> <?php endif; ?>
Also โ in what location should I place this hook (before_main_content)?
And lastly โ I presume that I tick the “Execute PHP” button? ๐
December 31, 2018 at 10:23 am #770028Leo
StaffCustomer SupportThis is all you need if you use the Hook Element:
<div class="entry-meta"> <?php generate_posted_on(); ?> </div>
That depends on where you want it to show:
https://docs.generatepress.com/article/hooks-visual-guide/And yes check execute PHP ๐
January 2, 2019 at 3:34 pm #771531culpable
Yes! It’s working now ๐
Is there a way to reverse the order in which it shows the dates (i.e. display “Published ____ & Last updated ____”)?
It’s currently showing: https://imgur.com/a/Voskp7n
And I’m using the following CSS code along with your hook above:
.posted-on .updated { display: inline-block; } .posted-on .updated:before { content: "Last updated "; } .posted-on .updated:after{ content: " &" } .posted-on .published:before { content: " Published "; }
Thank you for your time Leo ๐
January 2, 2019 at 7:56 pm #771637Leo
StaffCustomer SupportAny chance you can link me to the page in question?
January 3, 2019 at 3:35 am #771839culpable
Sure thing Leo โ image and link here
January 3, 2019 at 1:03 pm #772460Leo
StaffCustomer SupportJanuary 4, 2019 at 4:16 am #772790culpable
I tried adding the code in the same hook as your previous suggestion:
<div class="entry-meta"><?php generate_posted_on(); ?></div> <?php add_filter( 'generate_post_date_output', function( $output ) { $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_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() ) ); echo sprintf( '<span class="posted-on">%1$s</span>', // WPCS: XSS ok, sanitization ok. sprintf( '<a href="%1$s" title="%2$s" rel="bookmark">%3$s</a>', esc_url( get_permalink() ), esc_attr( get_the_time() ), $time_string ) ); } ); ?>
But it doesn’t seem to be working. Did I enter it in wrong? (highly likely, sorry Leo)
Also Leo as per this link, I just noticed my author pages aren’t showing anything.
I’m guessing this is because I have no posts, only pages. Is there code I can add to fix this? If so, can you show me how I have to wrap PHP code such that it executes within the Elements hook โ would this require a display rule on Author archive pages?
Otherwise, if it’s easier I can add the code to display the authored pages as a PHP snippet.
January 4, 2019 at 10:37 am #773208Leo
StaffCustomer SupportTom’s code needs to be added separately as a PHP function.
Adding PHP: https://docs.generatepress.com/article/adding-php/
January 4, 2019 at 4:51 pm #773431culpable
Working!!!
Since the author question is separate, I’ll make a new post for that.
Thank you very much for your time Leo.
January 4, 2019 at 5:27 pm #773456Leo
StaffCustomer SupportNo problem ๐
-
AuthorPosts
- You must be logged in to reply to this topic.