• Here’s a question I was pondering today: Would there be a way to create a widget that automatically displays the most recent revision date for a specific page or policy? For example, I’m thinking of a widget that would show the most recent revision date for a site’s privacy policy or terms of use.

    I know that get_the_title and get_the_modified_date will return the title and modified date for a specific post or page, but how would one incorporate that into a widget to actually place the output on a page?

Viewing 10 replies - 1 through 10 (of 10 total)
  • I would not recommend using a widget to do that.

    Post Title Goes Here
    Last Modified: 17 March 2020

    Post content goes here.

    You could simply add get_the_modified_date to your theme’s template file.

    Thread Starter Ate Up With Motor

    (@ate-up-with-motor)

    @carike Is there a particular technical or procedural reason you would not recommend using a widget to do that?

    The most obvious limitation I can see is that if it’s dependent on a function in the theme’s functions.php file, the widget would not work after switching themes. Is there some other technical issue beyond that?

    The reason I’d like to do it in a widget is that I have an existing widget for this purpose that has to be continually updated manually. I would prefer to keep the existing placement (since visitors know where it is) and automate the last modified date (so that I don’t have to worry about remembering that extra step. Adding it to the page template files would accomplish the second, but greatly complicate the first, which is not an ideal solution.

    You would not enter it into the theme’s functions.php file.
    You would enter it into the theme’s relevant page template itself.
    Yes, that does mean that it would no longer appear if you switch themes.

    There are two main reasons why I would not put it in a widget:
    – At present, widgets cannot be placed into a post area. So the placement might not look natural in a widget.
    Of course, this could be done in a Gutenberg block instead of a widget, in which case the above would not apply. Incidentally it would also not go away if you changed themes.
    – While widgets are indeed wonderful, they require significantly more knowledge about coding than including the modified date in the theme’s file.

    Thread Starter Ate Up With Motor

    (@ate-up-with-motor)

    @carike — Well, regarding your first reason, placement is exactly the reason I WANT to put it in a widget. I’m not trying to put this information in the post area. The goal is to replace an existing sidebar widget that serves the same function, but must be updated manually with each update. If I forget to do so, it defeats the purpose of the widget.

    Building it into a theme layout would require recreating a bunch of core parent theme elements in a child theme, which creates the risk of causing technical problems when the parent theme is next updated. Worse, the risk in that case might not be obvious right away, which makes me uneasy. I use child themes, but I try not to recreate or replace more of the parent theme code than I have to, mostly to avoid that kind of problems.

    I’m aware that widgets require more coding knowledge, but that’s why I asked this question in the first place.

    I don’t use, or even understand, the Gutenberg block editor, so that is irrelevant to me. (I find it frustrating that WordPress is trying to push the block editor, honestly; why reinvent the wheel in such an unfamiliar, non-intuitive manner, which just confuses and frustrates the many users who aren’t developers? But, that’s another matter.)

    Is there some technical reason why placing that in a widget wouldn’t work reliably or would cause problems? If so, that might be a good reason not to do it at all; I don’t think placing the code in theme files would be at all prudent for me.

    Also, I’m puzzled by why Vasim Shaikh’s earlier reply (which outlined a way to execute exactly what I was proposing) was removed. I don’t know if Vasim did so himself, but if there’s some technical problem with the solution he proposed on Feb. 23, it seems like it would have been better to publish a correction rather than simply remove it.

    Entering it into a child theme would not require a massive re-write of the code.
    It would require a single additional line in the right theme file.

    I think it is already clear that I was not “trying to push” any particular solution, but discussing a variety of solutions – one of which is indeed creating a re-usable block in the Gutenberg editor.

    The “technical” reason why I am not recommending a widget in this case is that that requires significant knowledge of validation, sanitizing and escaping (levels of magnitude more than the other options discussed).

    Which option you choose is not under my control – and I would not want it to be.
    That having been said, I am choosing to step away from this particular conversation at this particular time.

    Thread Starter Ate Up With Motor

    (@ate-up-with-motor)

    Did you delete Vasim Shaikh’s earlier reply of February 23? If so, and if the reason was that there was some technical problem or flaw with it, I’d rather you said so plainly rather than leaving me to guess.

    If you don’t feel qualified to answer my questions, you certainly aren’t obliged to try. However, Gutenberg (which I do not and will not use) is not a viable alternative, so it is not an answer to my question, nor is adding code to the theme file, which would not allow me to place the output in the way I want and WOULD likely create technical problems.

    I did not delete any replies.

    I do feel qualified to answer your questions, I just don’t want to (and I am under no such obligation, nor is anyone else here).

    If you have an issue with possible moderation on this thread, you are welcome to join Slack here: https://make.www.ads-software.com/chat/
    The appropriate channel is called #forums.

    Thread Starter Ate Up With Motor

    (@ate-up-with-motor)

    I am well aware the forums are answered on a volunteer basis. However, stepping in just to say, “I know how to answer your question, but I don’t want to,” seems like a peculiar use of your time and helps no one.

    It’s very seldom (if ever) that an answer will be deleted solely on technical issues. Those are usually left on their own with a reply that provides a better or proper answer.

    Only moderators here are privy to deleted content and the reasons for deletion… The poster of such deleted content should have received an email communication from the moderator and/or an ‘invite’ to discuss the issue over on Slack.

    Thread Starter Ate Up With Motor

    (@ate-up-with-motor)

    @jnashhawkins That would make sense, which is why I found it odd. I don’t know Vasim Shaikh, so I’m not in a position to ask him about it.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Widget showing last revision date of post or page’ is closed to new replies.