To isolate the adjustment to only when the name is showing, we'll just semi-recreate the original function managing the buff container.
Lua Code:
hooksecurefunc(NameplateBuffContainerMixin,"UpdateAnchor",function(self)
local parent=self:GetParent();
local unit=parent.unit;
if unit and ShouldShowName(parent) then
-- Replicate the calculation of the original function
local offset=self:GetBaseYOffset()+((unit and UnitIsUnit(unit,"target")) and self:GetTargetYOffset() or 0);
self:SetPoint("BOTTOM",parent,"TOP",0,offset);-- Apply offset here
end-- We'll leave the false side of this alone to preserve the original anchor in that case
end);