We're merging with GenerateBlocks! Learn more here.

[Resolved] Display Meta Without Link

Please login to receive premium support.

Support for the free plugin can be found here.

Home Forums Pro Support Display Meta Without Link

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #30513
    Sean
    Participant

    I 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?

    #30529
    elvin
    Moderator

    Hi 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/

    #30538
    Sean
    Participant

    Hi 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.

    #30554
    elvin
    Moderator

    Ah 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
    	); 
    });
    #30558
    Sean
    Participant

    Hi 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.

    #30564
    elvin
    Moderator

    I 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.

    #30566
    Sean
    Participant

    Hi Elvin,

    Works like a charm… Thanks for your help.

    #30595
    elvin
    Moderator

    Nice one. No problem. Glad to be of any help. 😀

    #32720
    Xavier
    Participant

    Hi 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);
    #32735
    elvin
    Moderator

    Hi 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.

Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.