This is a straightforward adaptation of moewe's answer to "Custom bib style for entries containing editor" (if this works for you, go upvote it too!).
First, add the following code to your preamble. This will make biblatex write "archived on" for references which include options = {archived}, and the default string otherwise.
% define a new "archivedon" string as an alternative to "urlseen"
\NewBibliographyString{archivedon}
\DefineBibliographyStrings{english}{
archivedon = {archived on}
}
% for each reference, detect if the "archived" option is used and set the urldate string accordingly
\newtoggle{bib:archived}
\DeclareEntryOption{archived}[true]{%
\settoggle{bib:archived}{#1}}
\DeclareFieldFormat{urldate}{%
\mkbibparens{%
\iftoggle{bib:archived}
{\bibstring{archivedon}} % "archived" option is on - write "archived on"
{\bibstring{urlseen}} % "archived" option is off - write "visited on"
\addcolon\space#1}}
Then you have one or two options, depending on what bibliography backend (bibtex or biber) you use:
a) If you use bibtex or don't want to automate this part, you'll need to edit your .bib file and add options = {archived} to all the references where you want to use "archived on":
@online{stack,
author = {{Stack Exchange Inc}},
title = {Stack Overflow},
url = {https://web.archive.org/web/20100813082822/http://www.stackoverflow.com/},
year = {2010},
urldate = {2010-08-13},
options = {archived}
}
b) If you use biber, you don't need to edit the .bib file, as it can set the archived option automatically (this doesn't work with bibtex):
% automatically add the "archived" option when reference url contains "archive.org"
\DeclareSourcemap{
\maps[datatype=bibtex]{
\map[overwrite]{
\step[fieldsource=url, match=\regexp{archive\.org},final]
\step[fieldset=options, append, fieldvalue={archived=true}]
}
}
}
MWE for bibtex (requires editing your .bib file to add the archived option to archive.org references):
\documentclass{article}
\usepackage{filecontents}
\begin{filecontents}{citations.bib}
@online{wikipedia,
author = {{Wikimedia Foundation}},
title = {Wikipedia},
url = {https://en.wikipedia.org},
year = {2019},
urldate = {2019-12-09}
}
@online{stack,
author = {{Stack Exchange Inc}},
title = {Stack Overflow},
url = {https://web.archive.org/web/20100813082822/http://www.stackoverflow.com/},
year = {2010},
urldate = {2010-08-13},
options = {archived}
}
\end{filecontents}
\usepackage[style=authoryear,backend=bibtex,urldate=long]{biblatex}
\addbibresource{citations.bib}
% use "archived on" instead of "visited on" when bib entry includes "options = {archived}"
% (inspired by https://tex.stackexchange.com/a/265929)
\NewBibliographyString{archivedon}
\DefineBibliographyStrings{english}{
archivedon = {archived on}
}
\newtoggle{bib:archived}
\DeclareEntryOption{archived}[true]{%
\settoggle{bib:archived}{#1}}
\DeclareFieldFormat{urldate}{%
\mkbibparens{%
\iftoggle{bib:archived}
{\bibstring{archivedon}}
{\bibstring{urlseen}}%
\addcolon\space#1}}
%-----
\begin{document}
Lorem ipsum dolor sit amet \autocite{wikipedia}, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua \autocite{stack}.
\printbibliography
\end{document}
MWE for biber (automatic, no .bib edits needed):
\documentclass{article}
\usepackage{filecontents}
\begin{filecontents}{citations.bib}
@online{wikipedia,
author = {{Wikimedia Foundation}},
title = {Wikipedia},
url = {https://en.wikipedia.org},
year = {2019},
urldate = {2019-12-09}
}
@online{stack,
author = {{Stack Exchange Inc}},
title = {Stack Overflow},
url = {https://web.archive.org/web/20100813082822/http://www.stackoverflow.com/},
year = {2010},
urldate = {2010-08-13}
}
\end{filecontents}
\usepackage[style=authoryear,backend=biber,urldate=long]{biblatex} % changed to biber
\addbibresource{citations.bib}
% use "archived on" instead of "visited on" when bib entry includes "options = {archived}"
% (inspired by https://tex.stackexchange.com/a/265929)
\NewBibliographyString{archivedon}
\DefineBibliographyStrings{english}{
archivedon = {archived on}
}
\newtoggle{bib:archived}
\DeclareEntryOption{archived}[true]{%
\settoggle{bib:archived}{#1}}
\DeclareFieldFormat{urldate}{%
\mkbibparens{%
\iftoggle{bib:archived}
{\bibstring{archivedon}}
{\bibstring{urlseen}}%
\addcolon\space#1}}
%----------
% for biber only - add the "archived" option automatically when url contains "archive.org"
\DeclareSourcemap{
\maps[datatype=bibtex]{
\map[overwrite]{
\step[fieldsource=url, match=\regexp{archive\.org},final]
\step[fieldset=options, append, fieldvalue={archived=true}]
}
}
}
%-----
\begin{document}
Lorem ipsum dolor sit amet \autocite{wikipedia}, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua \autocite{stack}.
\printbibliography
\end{document}