Using pdfLaTeX. I have created a new command
\newcommand{\singlefigure}[3]{
\begin{figure}
\label{fig:#2}
\centering
\caption{#3}
\includegraphics[trim={0cm 0cm 0cm 0cm},clip,height=0.2\textheight]{./fig/#1}
\end{figure}
}
having it in mind to speed up the coding of figures. Actually it suits me pretty well, at first since
\singlefigure{directory/file.jpg}{mylabel}{My caption}
gets me immediately where I want.
Likewise, I have created another shorthand to reference a figure
\newcommand{\fig}[1]{Figure~\ref{fig:#1}}
which works well except when I am referencing a figure created with \singlefigure above, say \fig{mylabel}.
The result is
Apparently I created a situation in which the label of the first command is not visible to the second one. Is there a remedy, correction or workaround for this glitch?
Similar posts:

\refcommand you will get??. When you compile the document a second time the reference appears. If this is not your problem then rather than posting code fragments please post a minimal working example, which compiles, so that people can replicate your problem. Btw, rather then defining\figyou might want to use\autoreffrom hyperref or\creffrom cleveref. – Sep 07 '20 at 05:58\labelmust always come after the\caption. – Phelype Oleinik Sep 07 '20 at 10:17