- This topic has 16 replies, 3 voices, and was last updated 1 year, 2 months ago by
Fernando.
-
AuthorPosts
-
July 9, 2022 at 8:27 am #2277998
Usman
Hey everyone,
I want to change my metadata from (private link) to https://www.imblogger.in/essential-blogging-tools-arsenal/
Looking forward if someone assist me better.
July 9, 2022 at 11:31 am #2278097Leo
StaffCustomer SupportHi there,
This should help:
https://docs.generatepress.com/article/block-element-post-meta-template/July 10, 2022 at 3:59 am #2278378Usman
Thank you @Leo, yes, it helped.
I updated my meta appearance. Now, I have 2 queries:
– I was using the estimated read time feature with custom PHP code. How can I add this manually now?
– How can I add | or – for space purposes. Should I add a paragraph in between for that?You can check the appearance, added the link in private. Please also review the appearance of the mobile screens.
Thanks 🙂
July 10, 2022 at 4:15 am #2278386Usman
* UPDATE
– I have added the spaces correctly.
– I want to replace the published date with the updated date. If I do so, the date disappears from the posts that haven’t any last modified date data.Looking Forward.
ThanksJuly 10, 2022 at 5:39 pm #2278843Fernando Customer Support
Hi Usman,
Let’s tackle the date first, then proceed with the estimated time afterwards.
First, add my-date-headline to the class list of the Headline Block for the modified date as such: https://share.getcloudapp.com/Wnu7DjAl
Then, add this PHP:
function db_rerender_modify_date( $block_content, $block ) { if ( ! is_admin() && ! empty( $block['attrs']['className'] ) && 'my-date-headline' === $block['attrs']['className'] ) { if ( get_the_date() == get_the_modified_date() ) { $time_string = '<time class="entry-date published" datetime="%1$s" itemprop="datePublished"> %2$s</time>'; $time_string = sprintf( $time_string, esc_attr( get_the_date( 'c' ) ), esc_html( get_the_date() ) ); $block_content = sprintf( '<span class="posted-on">%s</span> ', $time_string ); } return $block_content; } return $block_content; } add_filter( 'render_block', 'db_rerender_modify_date', 10, 2 );
Adding PHP reference: https://docs.generatepress.com/article/adding-php/#code-snippets
Kindly let us know how it goes.
July 10, 2022 at 8:00 pm #2278895Usman
Thanks, @Fernando, it worked.
But, it is causing appearance/structure issues on posts that haven’t any modified date data. I added private link.
Thanks again. 🙂
July 10, 2022 at 9:06 pm #2278930Fernando Customer Support
I see. Can you try this snippet instead:
add_filter('generateblocks_dynamic_content_output', function($content, $attributes, $block){ if ( ! empty( $attributes['className'] ) && strpos( $attributes['className'], 'my-date-headline' ) !== false ) { if ( get_the_date() == get_the_modified_date() ) { $time_string = '<time class="entry-date published" datetime="%1$s" itemprop="datePublished"> %2$s</time>'; $time_string = sprintf( $time_string, esc_attr( get_the_date( 'c' ) ), esc_html( get_the_date() ) ); $content = sprintf( '<span class="posted-on">%s</span> ', $time_string ); } return $content; } return $content; }, 10, 3);
Make sure the Dynamic Data is added through the Block Settings as such: https://share.getcloudapp.com/z8umQzkD
Kindly let us know how it goes.
July 10, 2022 at 9:22 pm #2278943Usman
Thanks again, @Fernando, now, the date option is working fine.
Before I was using this code for estimated time feature:
function tu_estimated_reading_time() { $post = get_post(); $content = $post->post_content; $wpm = 300; // How many words per minute. $clean_content = strip_shortcodes( $content ); $clean_content = strip_tags( $clean_content ); $word_count = str_word_count( $clean_content ); $time = ceil( $word_count / $wpm ); return $time . ' minutes'; } add_filter( 'generate_post_author_output', function( $output ) { $output .= '<span class="read-time"> · Read time: ' . tu_estimated_reading_time() . '</span>'; return $output; } );
July 10, 2022 at 9:44 pm #2278947Fernando Customer Support
How do you want it to appear? Attached to the date or a Headline Block of its own?
See: https://share.getcloudapp.com/12uLzWbA
Kindly let us know.
July 10, 2022 at 10:04 pm #2278954Usman
I can replace the category block with the estimated time if necessary otherwise on the last (after that category tags).
July 10, 2022 at 10:32 pm #2278969Fernando Customer Support
I see. Well, you don’t need to replace the Category Block. Just create a new Headline Block with this text:
text-to-replace
. Then, add this class to the Headline:my-estimated-headline
.Example: https://share.getcloudapp.com/yAu1QOwW
Then, add this PHP snippet:
function db_rerender_add_estimated_time( $block_content, $block ) { if ( ! is_admin() && ! empty( $block['attrs']['className'] ) && 'my-estimated-headline' === $block['attrs']['className'] ) { $post = get_post(); $content = $post->post_content; $wpm = 300; $clean_content = strip_shortcodes( $content ); $clean_content = strip_tags( $clean_content ); $word_count = str_word_count( $clean_content ); $time = ceil( $word_count / $wpm ); $my_search = 'text-to-replace'; $my_replace = $time . ' minutes'; $block_content = str_replace($my_search, $my_replace, $block_content); return $block_content; } return $block_content; } add_filter( 'render_block', 'db_rerender_add_estimated_time', 10, 2 );
Kindly let us know how it goes.
July 10, 2022 at 10:54 pm #2278976Usman
Yes, it worked fine. Thanks, man. 🙂
Please revise it for mobile users too. It is trying to adjust the entire script in one line which is causing issue for mobile users. Shouldn’t it go to second line according to screen sizes?
July 10, 2022 at 11:07 pm #2278980Fernando Customer Support
The code I provided shouldn’t affect your layout. Do you have inline-width enabled on Mobile? Can you try disabling it?
July 10, 2022 at 11:17 pm #2278992Usman
Mobile inline-width is disabled for each block but enabled for the entire container. At the container level, there isn’t any option to disable inline-width for mobile.
July 10, 2022 at 11:27 pm #2278994Fernando Customer Support
I see. You can either move the inline-width setting to the Headline Blocks, or add this CSS through Appearance > Customize > Additional CSS:
@media (max-width: 768px) { .gb-container.gb-container-8a25fc79 > .gb-inside-container { flex-wrap: wrap; } }
This allows wrapping for your Container Block on mobile.
Hope this clarifies!
-
AuthorPosts
- You must be logged in to reply to this topic.