Задумано так:
const nodeWPshortcodeLazyLoading = document.getElementById('WPshortcodeLazyLoading');
function WPshortcodeLazyLoading() {
const nodeWPshortcodeLazyLoadingPosition = nodeWPshortcodeLazyLoading.getBoundingClientRect().top;
if (nodeWPshortcodeLazyLoadingPosition - window.innerHeight < 400) {
const span = document.createElement('span');
span.innerText = '[visualizer id="2543"]';
nodeWPshortcodeLazyLoading.appendChild(span);
document.removeEventListener('scroll', WPshortcodeLazyLoading);
}
}
document.addEventListener('scroll', WPshortcodeLazyLoading);
Вероятно, между определением константы nodeWPshortcodeLazyLoading
и скроллом появляются новые блоки, которые ты или плагин пишет в DOM