';
$html .= sprintf(
'
%s',
esc_html($title)
);
$html .= '
';
foreach ($tocItems as $item) {
$text = $item['text'] ?? '';
$anchor = $item['anchor'] ?? '';
$level = $item['level'] ?? 2;
if (empty($text) || empty($anchor)) {
continue;
}
$indentClass = $level > 2 ? 'toc-level-' . $level : '';
$html .= sprintf(
'- %s
',
esc_attr($indentClass),
esc_attr($anchor),
intval($level),
esc_html($text)
);
}
$html .= '
';
$html .= '
';
return $html;
}
private function buildScript(array $data): string
{
$content = $data['content'] ?? [];
$behavior = $data['behavior'] ?? [];
$smoothScroll = $content['smooth_scroll'] ?? true;
$scrollOffset = intval($behavior['scroll_offset'] ?? 100);
if (!$smoothScroll) {
return '';
}
// Script con inyección de IDs client-side para mayor fiabilidad
// Resuelve problemas de orden de filtros WordPress y caché
$script = <<