0

I want to remove the last updated / last modified date from pages (not posts) via functions.php (could this be done by making that hook __null?)

The goal is to remove the google search result description date time stamp that shows up because of the date modified code. I only want the function to run on pages (since it usually doesn't matter when the page was last updated / created).

I realize this could be done by modifying the underlying code in the page template, but this method would be much easier to implement.

Thanks!

11
  • There is very little point in asking the same question again after it was closed as off-topic. The question do not become less off-topic if you ask it many times. Feb 18, 2015 at 19:28
  • What have you coded so far yourself? Please post your code. Feb 18, 2015 at 19:49
  • It was flagged as off topic because it alluded to plugins and themes. I think this is an issue enough people run into (as I see it enough in search results). Specifically anyone using Avada theme as it's one of the most downloaded. Feb 19, 2015 at 3:37
  • the reason it is off-topic is because you asking something which is related to 3rd party service. No one hs control on what google displays in their search results except for google therefor this question can not be answered in the context of SE unless a google employee answers it. Feb 19, 2015 at 4:26
  • Actually everyone has control on what Google Displays; especially in this case. Feb 19, 2015 at 18:13

2 Answers 2

1

It depends on what the template uses to output whatever you're trying to remove. If you look in source at whatever function is outputting what you want to remove, they each have a filter to let you modify output where you can __return_false instead, however, if there's text or markup surrounding those template tags, your only option is to modify the template, preferably via a child theme.

function wpd_remove_modified_date(){
    if( is_page() ){
        add_filter( 'the_time', '__return_false' );
        add_filter( 'the_modified_time', '__return_false' );
        add_filter( 'get_the_modified_time', '__return_false' );
        add_filter( 'the_date', '__return_false' );
        add_filter( 'the_modified_date', '__return_false' );
        add_filter( 'get_the_modified_date', '__return_false' );
    }
}
add_action( 'template_redirect', 'wpd_remove_modified_date' );
9
  • I'm trying to make this as universal as possible. Both for myself and other people who Google this problem so they can figure out which solution to use if they're only looking to use a single filter. Feb 18, 2015 at 23:49
  • 1
    there is no universal solution, it will depend on the theme.
    – Milo
    Feb 18, 2015 at 23:51
  • I thought there are only so many hooks that print out the date... some themes print it out in the source but do not actually display it on page (for posts the date is usually visible and not just hidden in the source). Also, using the code above made my admin area go white if I use it in the code-snippets plugin. Had to remove the folder from plugin folder to deactivate it. Is there a quick way to remove/deactivate the snippet? Feb 19, 2015 at 0:44
  • 1
    There isn't anything in the code that would trigger an error, so I don't know why it wouldn't work with that code snippets plugin. I'd suggest not using those sorts of plugins anyway, as they cause more problems than they solve. Yes, there are only a handful of functions that output date, but consider the case where a theme prints the text "modified on:" followed by the function to output the modified date. You'd then have "modified on:" text on your pages with no date being printed, which I'd guess would not be desirable.
    – Milo
    Feb 19, 2015 at 1:51
  • Via a child theme you could then use CSS to display:none on the particular element that surrounds modified on:. That way you don't have to modify the php file itself. This method of CSS only is not enough to prevent a search engine like google from using the element in search result listings. Could you clarify this: if I use a functions.php file in my child theme I have to constantly modify it when the parent theme's functions.php file gets updated. The code snippets plugin saves me from having to constantly mess with any php file in the way I'm describing? Feb 19, 2015 at 2:34
0

All of the code needed to work:

function wpd_remove_modified_date(){
    if( is_page() ){
        add_filter( 'the_time', '__return_false' );
        add_filter( 'the_modified_time', '__return_false' );
        add_filter( 'get_the_modified_time', '__return_false' );
        add_filter( 'the_date', '__return_false' );
        add_filter( 'the_modified_date', '__return_false' );
        add_filter( 'get_the_modified_date', '__return_false' );
    }
}
add_action( 'template_redirect', 'wpd_remove_modified_date' );

I use a plugin called Code Snippets to have this code run on all sites in my wordpress multisite installation.

Not the answer you're looking for? Browse other questions tagged or ask your own question.