[Resolved] Removing link for date

Home Forums Support [Resolved] Removing link for date

Home Forums Support Removing link for date

Viewing 15 posts - 1 through 15 (of 15 total)
  • Author
    Posts
  • #1088493
    Oleksiy

    Hi, guys. Could you please help me with the following issue. Task is to move the date to the bottom and remove the link.

    First I’ve added this code to remove the link for the date when it was at the top (by default) – https://gist.github.com/generatepress/429d8f954419921f564f. It worked.

    But then I moved date to the bottom. Used this code https://gist.github.com/generatepress/cf95fae85d5e7773d97a from this topic – https://generatepress.com/forums/topic/move-author-date-to-the-bottom-after-content/. The link for the date appeared again.

    Code is added in the functions.php in the child theme. First – “moving to the bottom” code, followed by “link removal”. The date disappears from the top even without using .css code:
    .entry-header .entry-meta {
    display: none;
    }

    How can I remove the link?

    #1088599
    Leo
    Staff
    Customer Support

    Hi there,

    You can actually use this filter to move the date link now:
    https://docs.generatepress.com/article/generate_footer_entry_meta_items/

    Then this snippet should remove the link:
    https://docs.generatepress.com/article/generate_post_date_output/#remove-link-from-date

    Adding PHP: https://docs.generatepress.com/article/adding-php/

    Let me know if this helps 🙂

    #1089304
    Oleksiy

    Thanks a lot, Leo. It works, and with a much more compact piece of code 🙂

    Is there also such compact solution to remove a link for the date in comments? I used this one – https://gist.github.com/generatepress/21b8e4b706caf59470b7. It works correctly, but I feel like it can be a shorter solution.

    Also there is a question about date text. I’ve used “before” and “after” in the CSS to display “Published” and “Last updated”:

    .posted-on .updated {
    display: inline-block;
    }

    .posted-on .updated:before {
    content: “Last updated: ”
    }

    .posted-on .updated:after {
    content: ” |”
    }

    .posted-on .published:before {
    content: ” Published: ”
    }

    But in this case words “Published” and “Last updated” are absent in the HTML source code. It means that they are invisible for search engines. That’s not great. How can I display them in the other way, to make them present in the source code?

    #1089778
    David
    Staff
    Customer Support

    Hi there,

    there isn’t a filter for changing the comment date link so unfortunately that solution is the way to go.

    This is the HTML for your date time elements:

    <time class="entry-date published" datetime="2019-11-23T18:30:53+02:00" itemprop="datePublished">23.11.2019</time>

    The itemprop="datePublished" schema markup will be recognised by search engines.

    #1089931
    Oleksiy

    Ok. Thanks, David.

    #1090014
    David
    Staff
    Customer Support

    You’re welcome

    #1097654
    Haider Ali

    Hello @Leo

    The date link does not remove for Example 2 listed here:
    https://docs.generatepress.com/article/entry-meta-style/

    Please help.

    Hi there,

    You can actually use this filter to move the date link now:
    https://docs.generatepress.com/article/generate_footer_entry_meta_items/

    Then this snippet should remove the link:
    https://docs.generatepress.com/article/generate_post_date_output/#remove-link-from-date

    Adding PHP: https://docs.generatepress.com/article/adding-php/

    Let me know if this helps 🙂

    #1097960
    Tom
    Lead Developer
    Lead Developer

    In Example 2, find this:

    <a href="%1$s" title="%2$s" rel="author"><span class="author-name" itemprop="name">%3$s</span></a>

    And replace it with this:

    <span class="author-name" itemprop="name">%3$s</span>

    #1097986
    Haider Ali

    Thanks for your reply Tom.

    However, this removed the link from the Author name and not the date.

    #1098139
    Tom
    Lead Developer
    Lead Developer

    Ah, sorry. In that case, this would be your code:

    add_filter( 'generate_post_author', '__return_false' );
    add_filter( 'generate_post_date_output', function( $date, $time_string ) {
        printf( 
            '<span class="meta-gravatar">%s</span>',
            get_avatar( get_the_author_meta( 'ID' ) )
        );
    
        echo '<span class="meta-data">';
    
        printf( ' <span class="byline">%1$s</span>',
            sprintf( '<span class="author vcard" itemtype="http://schema.org/Person" itemscope="itemscope" itemprop="author"><a href="%1$s" title="%2$s" rel="author"><span class="author-name" itemprop="name">%3$s</span></a></span>',
                esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
                esc_attr( sprintf( __( 'View all posts by %s', 'generatepress' ), get_the_author() ) ),
                esc_html( get_the_author() )
            )
        );
    
        printf( // WPCS: XSS ok, sanitization ok.
            '<span class="posted-on">%1$s%4$s</span> ',
            apply_filters( 'generate_inside_post_meta_item_output', '', 'date' ),
            esc_url( get_permalink() ),
            esc_attr( get_the_time() ),
            $time_string
        );
    
        echo '</span>';
    }, 10, 2 );
    #1098375
    Haider Ali

    It worked! Thank you so much Tom

    #1098450
    Alex

    Hi! Thanks for your great support here. I’ve also tried to apply this code

    add_filter( ‘generate_post_date_output’, function( $output, $time_string ) {printf( ‘<span class=”posted-on”>%s</span>’, $time_string);}, 10, 2 );

    It works OK, but the date and “by” are put together and the entry meta reads like this:
    July 9, 2019by Author. Is there a way to separate them?
    Thanks for your reply!

    #1098538
    David
    Staff
    Customer Support

    Hi there,

    try inserting a space after the s in this code:

    <span class=”posted-on”>%s</span>

    ie.

    <span class=”posted-on”>%s </span>

    #1099510
    Alex

    Thank you! So easy 🙂

    #1099678
    David
    Staff
    Customer Support

    Glad to be of help

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