[Resolved] Remove dateModified from HTML

Home Forums Support [Resolved] Remove dateModified from HTML

Home Forums Support Remove dateModified from HTML

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #1082939
    Chris

    Hi,

    Is it possible to remove Modified Date from the HTML, rather than just hiding it with CSS?

    #1085171
    Tom
    Lead Developer
    Lead Developer

    You don’t want the modified date at all? If not, try this PHP:

    add_filter( 'generate_post_date_output', function( $output, $time_string ) {
        $time_string = '<time class="entry-date published" datetime="%1$s" itemprop="datePublished">%2$s</time>';
    
        $time_string = sprintf( $time_string,
            esc_attr( get_the_date( 'c' ) ),
            esc_html( get_the_date() )
        );
    
        return sprintf( '<span class="posted-on">%s</span> ',
            $time_string
        );
    }, 10, 2 );

    Let me know πŸ™‚

    #1090175
    Chris

    Hi Tom,

    Thanks for this but it doesn’t seem to have worked. I can still see the date in the html, with display: none; set. I have edited my initial post to show the URL

    Out of interest, why do you hide it with CSS rather than remove it with PHP when a user has opted not to include it in the GP settings? πŸ™‚

    #1090778
    Tom
    Lead Developer
    Lead Developer

    Are you already using a function to alter the post meta/date? Your HTML on the site doesn’t reflect the function I mentioned above.

    The GP setting to remove the date should fully remove the date from the HTML.

    Let me know πŸ™‚

    #1091312
    Chris

    Ah yes you were correct, I had some more code in there so I have now combined the two.

    Also, apologies as I was mistaken about the setting to remove the date.

    I had misremembered and thought there were separate options to show Date Published and Date Modified, but there is only a single option to control the date being shown.

    My concern with hiding things via CSS is that it can look deceptive from an SEO point of view. I don’t think that is an issue here, but I prefer to just remove it if it is not being used.

    #1091995
    Tom
    Lead Developer
    Lead Developer

    In most cases, Google knows whether you’re being deceptive or not.

    Did you get the above function working now?

    Let me know πŸ™‚

    #1092870
    Chris

    Yes I did, thank you.

    #1093494
    Tom
    Lead Developer
    Lead Developer

    Awesome, no problem πŸ™‚

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