- This topic has 5 replies, 2 voices, and was last updated 3 years, 2 months ago by Elvin.
-
AuthorPosts
-
January 12, 2021 at 3:12 pm #1616350andrachans
Hello there,
The code below was previously supplied to me under support ticket of June 24, 2018.
Can you please assist me with the following:
1) Remove the word ‘by’ from the .byline
2) On the Archive page, keeping the single line layout, drop the entry-meta below the entry-summary.
3) On the Single post, keep the entry-meta where it is, below the entry-title.
4) Allow me to control which entry-meta displays on the Archive page and Single post, through the Customizer. Currently, the ticking of boxes / unticking of boxes in the Customizer, has no affect on the entry-meta that is displayed – it is either all there, or, nothing is there if I untick the ‘Display post author’ box.Thank you.
Kallad
add_filter( ‘generate_post_author_output’, ‘tu_categories_to_author’ );
add_filter( ‘generate_category_list_output’, ‘__return_false’ );
add_filter( ‘generate_tag_list_output’, ‘__return_false’ );
add_filter( ‘generate_show_comments’, ‘__return_false’ );
add_filter( ‘generate_post_date_output’, ‘__return_false’ );
function tu_categories_to_author( $output ) {
$categories_list = get_the_category_list( _x( ‘, ‘, ‘Used between list items, there is a space after the comma.’, ‘generatepress’ ) );
$categories_list = sprintf( ‘<span class=”cat-links”>%1$s</span>’,
$categories_list
);$tags_list = get_the_tag_list( ”, _x( ‘, ‘, ‘Used between list items, there is a space after the comma.’, ‘generatepress’ ) );
$tags_list = sprintf( ‘<span class=”tags-links”>%1$s</span>’,
$tags_list
);$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 class=”updated” datetime=”%3$s” itemprop=”dateModified”>%4$s</time>’ . $time_string;
}$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() )
);$date = sprintf( ‘<span class=”posted-on”>%1$s</span>’, // WPCS: XSS ok, sanitization ok.
sprintf( ‘%3$s‘,
esc_url( get_permalink() ),
esc_attr( get_the_time() ),
$time_string
)
);echo $output . ‘ | ‘ . $date . ‘ | ‘ . $categories_list . ‘ | ‘ . $tags_list;
}
January 12, 2021 at 5:38 pm #1616431ElvinStaffCustomer SupportHi,
1.) You can follow Tom’s code here to remove the byline:
https://generatepress.com/forums/topic/removing-by-from-author-byline/#post-5438822, 3 and 4.)
You can control the entry meta display by using
generate_header_entry_meta_items
andgenerate_footer_entry_meta_items
filters.You can add in page/post conditions to the filter to control their display on posts, archives and pages.
Example:
add_filter('generate_header_entry_meta_items', function(){ if(is_archive() || is_home()){ //if its an archive page or blog return array( 'date', 'author', ); } if(is_search()){ //if search page return array( 'date', 'categories', ); } if(is_singular()){ //if single page } });
That said, for #2 and #3:
add_filter('generate_header_entry_meta_items', function($items){ if(is_archive() || is_home()){ //if its an archive page or blog return false; } return $items; }); add_filter('generate_footer_entry_meta_items', function($items){ if(is_archive() || is_home()){ //if its an archive page or blog return array( 'date', 'author', 'comments-link', 'categories', 'post-navigation', ); } return $items; });
January 13, 2021 at 3:09 pm #1617762andrachansThank you for your reply.
1) Apologies – this was my mistake – I did previously read this solution on the support forum.
2, 3, 4) This is not quite what I am after. Let me start again:
On the Archive page, I want the entry-meta in a single, positioned below the entry-summary.
On the Single post, I want the entry-meta in a single line, positioned below the entry-title.
I want to still be able to use the Customizer to hide / display different entry-meta, on the Archive page and Single post (like I can do before having entry-meta placed on a single line).
I do not want to add hooks, etc, as I am not a developer, and this is looking for trouble for me. A simple solution will work best for me.Thank you.
January 13, 2021 at 3:52 pm #1617797ElvinStaffCustomer SupportThe theme has 2 entry meta locations on its archive and and single posts page.
1 is on header .entry-meta after the entry-title and 1 on the footer after the content or entry-summary on posts lists.
The purpose of the filter was to be able to control or move the entry meta placed on the header .entry-meta to the footer .entry-meta. The condition is then added so it only applies for the archive pages as per your requirement.
Once moved, you can style it with CSS for it to stay on a single line.
I want to still be able to use the Customizer to hide / display different entry-meta, on the Archive page and Single post (like I can do before having entry-meta placed on a single line).
You can still use this even after adding the filter.
I do not want to add hooks, etc, as I am not a developer, and this is looking for trouble for me. A simple solution will work best for me.
Unfortunately, you’ll have to use the filter if you want to specifically control and/or move entry meta items to other locations as it’s not within the customizer UI.
Here’s how to add PHP incase you’ve decided to use it:
https://docs.generatepress.com/article/adding-php/February 11, 2021 at 12:52 pm #1655005andrachansHello there,
Apologies for the late response.
I will do so…thank you.
Kallad
February 11, 2021 at 7:16 pm #1655210ElvinStaffCustomer SupportNo problem. Let us know how it goes.
-
AuthorPosts
- You must be logged in to reply to this topic.