The more I look at this picture the more I doubt this is the City God's Temple in Shanghai. Why is there a steep staircase leading up to the temple? Why does the gateway building look like nothing inside Shanghai's temple today? After a fire in 1924 the temple was rebuilt extensively and made to look more like an ancient Chinese temple structure, with upturned eaves and pavilions, as some Chinese sources say. But would they really have flattened the mound the temple stood on? Below is a photo of the interior courtyard of the temple in the 1920s, but it is unclear if it's taken before or after reconstruction:
And here is the temple entrance in the 1980s (from the book Ancestors). The gateway building is not a even a five-bay structure like at the photo above:
The signboard over the entrance is hard to decipher, but I'm practically sure it goes like 宫 行 ＊ 天 ＊ ＊, and I'm tempted to think it is 东＊天後行宫, or a Temporary Temple of the Queen of Heaven (if I interpret "xinggong" correctly). The only problem is 後 does not look very believable.
The only Temple of the Queen of Heaven in Shanghai that was known as 天后行宫 and not 天后宫 was Zhening Guildhall in the docks. This is the drawing of the guildhall, and it does not have any close similarity to the high steps in the photo above.
The image in the Stafford Collection is either some other temple in Shanghai, or a temporary Temple of the Queen of Heaven somewhere else.