- This topic has 16 replies, 4 voices, and was last updated 5 months, 1 week ago by
Tom.
-
AuthorPosts
-
August 13, 2020 at 2:05 pm #1401629
Alessio
Hey,
I’m currently using this PHP code to make the featured image clickable (using WP Featherlight) and to add the date and author:
add_filter( 'generate_single_featured_image_output', function( $output, $image_html ) { printf( '<div class="featured-image"> <a href="%1$s"> %2$s </a> </div> <div class="sdate"> %3$s </div> ', get_the_post_thumbnail_url(), $image_html, generate_posted_on(), ); }, 10, 2 );
However, the date & name is shown above the featured image:
I want it be shown below the featured image, though.
Also, can anyone explain what the}, 10, 2 );
in the PHP-code does?Thank you!!
August 13, 2020 at 3:31 pm #1401726Leo
StaffCustomer SupportHi there,
Any chance you can link us to the site in question?
You can edit the original topic and use the private URL field.
Let me know 🙂
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/August 13, 2020 at 3:33 pm #1401727Alessio
Hi,
I’ve edited it. Both password and username is 111111
August 14, 2020 at 2:57 am #1402266David
StaffCustomer SupportHi there,
try this function to move the date:
add_action( 'wp', function() { if ( is_single() ) { remove_action( 'generate_after_entry_title', 'generate_post_meta' ); add_action( 'generate_before_content', 'generate_post_meta', 15 ); } } );
the
10 , 2 );
10
= the priority in which function callbacks are executed when attached to a hook. There could be more than one function attached. The one with the lower number gets executed first.2
= is the number of accepted arguments the add_filter requires. In this case 2 which are $output & $image_html.Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/August 14, 2020 at 7:29 am #1402613Alessio
Hi there,
the function sadly doesn’t have any effect at all. Maybe because it’s a page and not a post?
August 14, 2020 at 8:04 am #1402818David
StaffCustomer Supportaah… how are you displaying the date and author on the single page?
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/August 14, 2020 at 8:06 am #1402822Alessio
With my php code:
add_filter( 'generate_single_featured_image_output', function( $output, $image_html ) { printf( '<div class="featured-image"> <a href="%1$s"> %2$s </a> </div> <div class="sdate"> %3$s </div> ', get_the_post_thumbnail_url(), $image_html, generate_posted_on(), ); }, 10, 2 );
I’ve added the
generate_posted_on()
at the bottom. And tried to insert it like this:<div class="sdate"> %3$s </div>
August 14, 2020 at 12:49 pm #1403214Tom
Lead DeveloperLead DeveloperHi there,
generate_posted_on()
won’t work in a filter like that.Instead, you should do something like this:
add_action( 'generate_after_entry_header', function() { if ( is_singular( 'page' ) ) { generate_posted_on(); } }, 20 );
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentAugust 14, 2020 at 12:53 pm #1403220Alessio
Hi,
this adds the date before the content:
How can I add it right after the featured image though?
August 14, 2020 at 12:57 pm #1403228Tom
Lead DeveloperLead DeveloperWhere is the featured image set to display? After the title?
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentAugust 14, 2020 at 12:59 pm #1403229Alessio
Yep, after the title!
August 14, 2020 at 1:00 pm #1403230Alessio
August 14, 2020 at 1:02 pm #1403232Tom
Lead DeveloperLead DeveloperTry the updated code here: https://generatepress.com/forums/topic/displaying-date-author-under-featured-image-in-pages/#post-1403214
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentAugust 14, 2020 at 1:03 pm #1403233Alessio
That’s working, thank you!!
How can I put the date & author inside of a div?August 14, 2020 at 1:05 pm #1403236Tom
Lead DeveloperLead DeveloperLike this:
add_action( 'generate_after_entry_header', function() { if ( is_singular( 'page' ) ) { echo '<div class="your-div-class">'; generate_posted_on(); echo '</div>'; } }, 20 );
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-development -
AuthorPosts
- You must be logged in to reply to this topic.