Home › Forums › Pro Support › Display Meta Without Link
- This topic has 9 replies, 3 voices, and was last updated 2 years, 1 month ago by
elvin.
-
AuthorPosts
-
May 23, 2021 at 3:36 am #30513
Sean
ParticipantI want to be able to display some meta information (date, author, etc) underneath the title of the post, but I want it to be informational only and not link to the post (in the case of the date) or to the author’s list of posts (in the case of the author).
Is there an easy way to do that?
May 23, 2021 at 5:31 pm #30529elvin
ModeratorHi Sean,
You’ll need to filter to remove the links.
Example/s:
For author –
add_filter( 'wpsp_author_output', function(){ return sprintf( '<span class="wp-show-posts-byline wp-show-posts-meta"> <span class="wp-show-posts-author vcard" itemtype="http://schema.org/Person" itemscope="itemscope" itemprop="author"> <span class="author-name" itemprop="name">%3$s</span> </span> </span>', esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ), esc_attr( sprintf( __( 'View all posts by %s', 'wp-show-posts' ), get_the_author() ) ), esc_html( get_the_author() ) ) });
For date –
add_filter( 'wpsp_date_output', function( $time_string ){ return sprintf( '<span class="wp-show-posts-posted-on wp-show-posts-meta"> <a href="%1$s" title="%2$s" rel="bookmark">%3$s</a> </span>', esc_url( get_permalink() ), esc_attr( get_the_time() ), $time_string ) });
For tags/categories –
add_filter( 'wpsp_terms_output', function( $output, $settings ) { return sprintf( '<span class="wp-show-posts-terms wp-show-posts-meta">%1$s</span>', strip_tags( get_the_term_list( get_the_ID(), $settings[ 'taxonomy' ], '', apply_filters( 'wpsp_term_separator', ', ' ) ) ) ); } ,15 ,2);
These are PHP codes. Here’s how to add PHP snippets to your site – https://docs.generatepress.com/article/adding-php/
May 23, 2021 at 11:30 pm #30538Sean
ParticipantHi Elvin,
Thanks for getting back to me – I tried to use the Date filter as above, but it’s throwing an error saying that it is expecting a “;” instead of the “}”.
If I add the semi-colon in:
add_filter( 'wpsp_date_output', function( $time_string ){ return sprintf( '<span class="wp-show-posts-posted-on wp-show-posts-meta"> <a href="%1$s" title="%2$s" rel="bookmark">%3$s</a> </span>', esc_url( get_permalink() ), esc_attr( get_the_time() ), $time_string ); });
The filter doesn’t throw an error but it also doesn’t remove the hyperlink from the Date.
May 24, 2021 at 3:19 am #30554elvin
ModeratorAh that’s right. my bad. I added the unedited filter.
Try this:
add_filter( 'wpsp_date_output', function( $time_string ){ return sprintf( '<span class="wp-show-posts-posted-on wp-show-posts-meta"> %3$s </span>', esc_url( get_permalink() ), esc_attr( get_the_time() ), $time_string ); });
May 24, 2021 at 3:28 am #30558Sean
ParticipantHi Elvin,
I’ve added that snippet to my functions.php in my child theme and it still doesn’t seem to be doing anything.
The date is still a hyperlink to the article.
May 24, 2021 at 5:09 am #30564elvin
ModeratorI see.
Let’s remove all the previously suggested code snippets for the
wpsp_date_output
filter.Try this instead.
add_filter( 'wpsp_date_output', 'tu_wpsp_remove_date_link' ); function tu_wpsp_remove_date_link() { $time_string = '<time class="wp-show-posts-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="wp-show-posts-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() ) ); printf( '<span class="wp-show-posts-posted-on wp-show-posts-meta">%1$s</span>', $time_string ); }
This one should work. Let us know how it goes.
May 24, 2021 at 6:16 am #30566Sean
ParticipantHi Elvin,
Works like a charm… Thanks for your help.
May 24, 2021 at 8:57 pm #30595elvin
ModeratorNice one. No problem. Glad to be of any help. 😀
August 4, 2021 at 11:11 am #32720Xavier
ParticipantHi I am trying to remove the links in meta tags and category, but the suggested code doesn’t work. Should I have to edit anything.
The page have multiple lists.
The code I am trying to use is this:
add_filter( 'wpsp_terms_output', function( $output, $settings ) { return sprintf( '<span class="wp-show-posts-terms wp-show-posts-meta">%1$s</span>', strip_tags( get_the_term_list( get_the_ID(), $settings[ 'taxonomy' ], '', apply_filters( 'wpsp_term_separator', ', ' ) ) ) ); } ,15 ,2);
August 4, 2021 at 8:05 pm #32735elvin
ModeratorHi Xavier,
The same code should work.
Can you tell us how you’ve added the code? also, do you have any other instances of the use of
wpsp_terms_output
filter?Let us know.
-
AuthorPosts
- You must be logged in to reply to this topic.