'How can I add static text to all \url{} items in Latex?

I have a bunch of \url{} items in my paper and I want to generate each of them automatically as follows: \url{https://www.asdf.com/} -> https://www.asdf.com/ (Last accessed in March 2022)

How can I redefine the latex \url{} command to introduce this hardcoded text snippet after each url it generates?



Solution 1:[1]

Assuming you are using the hyperref package:

\documentclass{article}

\usepackage{hyperref}

\makeatletter
\AddToHook{cmd/url@/after}{\textit{ (Last Accessed in March 2022)}}
\makeatother

\begin{document}

\url{https://www.asdf.com/}

\end{document}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 samcarter_is_at_topanswers.xyz