Archived topic
Prev/Next posts
15 replies · Started by manaadiar on October 7, 2020
Hi, after the latest GP updates, my meta tags are showing as below.. Can you pls assist in moving this to the bottom of the article.. What code must I change in the child theme to do this.. Pls click below link to see the error..
https://www.shippingandfreightresource.com/wp-content/uploads/GPERROR.png
Hi there,
what functions are you using to display the Post meta ?
Hi David, don't understand your question..
in the Post meta i have
October 7, 2020 by Hariesh Manaadiar
Categories : Climate Change, News, Press Release
Tags : Bulk, Climate Change, The Sea Cargo Charter
Leave a comment
Estimated reading time = 5 minutes
the issue is that
1) this is being duplicated
2) it is also bringing the PREV and NEXT links here
Both of this happened since the GP Premium update that was done today..
By default GP doesn't display all that Meta in that place.
So you must of added a PHP Snippet to display the meta ?
Yes, I had, but that was in my child theme.. See below code.. But something in the parent theme is overriding this and causing it to duplicate..
// Code to move cat/tags/comments to the top of the page - original deleted from post-meta.php
if ( ! function_exists( 'generate_post_meta' ) ) {
add_action( 'generate_after_entry_title', 'generate_post_meta' , 'generate_after_entry_content', 'generate_footer_meta' );
/**
* Build the post meta.
*
* @since 1.3.29
*/
function generate_post_meta() {
if ( 'post' == get_post_type() ) : ?>
<div class="entry-meta">
<?php generate_posted_on(); ?>
<?php
generate_entry_meta();
?>
Estimated reading time = <?php echo reading_time(); ?>
<?php endif;
}
}
// Code to show the next and previous post - original deleted from post-meta.php
if ( ! function_exists( 'generate_footer_meta' ) ) {
add_action( 'generate_after_entry_content', 'generate_footer_meta' );
/**
* Build the footer post meta.
*
* @since 1.3.30
*/
function generate_footer_meta() {
if ( 'post' == get_post_type() ) : ?>
<footer class="entry-meta">
<?php
if ( is_single() ) {
generate_content_nav( 'nav-below' );
}
?>
</footer><!-- .entry-meta -->
<?php endif;
}
}
Instead of that code, try this:
add_action( 'generate_post_meta_items', function( $item ) {
if ( 'reading-time' === $item ) {
echo 'Estimated reading time = ' . reading_time();
}
} );
add_filter( 'generate_header_entry_meta_items', function() {
return array(
'date',
'author',
'categories',
'tags',
'comments-link',
'reading-time',
);
} );
add_filter( 'generate_footer_entry_meta_items', function() {
return array(
'post-navigation',
);
} );
Hi Tom, it gave an error - something unexpected ' in line 63.. But when I copied the old post-meta.php file info into the new update, it worked fine..
That's not a great idea - it will likely result in more breakages, especially with future versions.
What was the exact error?
Ooops, can you let me have the latest post-meta.php file info, i can try replacing that and let you know the error..
This is the 3.0.0 post-meta.php file: https://raw.githubusercontent.com/tomusborne/generatepress/3.0.0/inc/structure/post-meta.php
This link (https://www.shippingandfreightresource.com/wp-content/uploads/GPerror-after-update.png) is the error after GP Premium updates..
This link (https://www.shippingandfreightresource.com/wp-content/uploads/GPerror-after-using-code.png) is the error after I use below code given by you
Instead of that code, try this:
add_action( 'generate_post_meta_items', function( $item ) {
if ( 'reading-time' === $item ) {
echo 'Estimated reading time = ' . reading_time();
}
} );
add_filter( 'generate_header_entry_meta_items', function() {
'date',
'author',
'categories',
'tags',
'comments-link',
'reading-time',
} );
add_filter( 'generate_header_entry_meta_items', function() {
return array(
'post-navigation',
);
} );
Pls advise, thanks..
Aha, can you try the updated code?: https://generatepress.com/forums/topic/prev-next-posts/#post-1477279
Hi Tom the site is now giving error after all these updates..
There has been a critical error on your website.
The code itself should be fine. Is there a specific error?
Is reading_time() a function you've added to your functions?
Hi, this is sorted now, thanks..