elementor main html tag – html structure – seo
-
hello, I was wondering how can i implement < main > html tag, in the correct way as for the html structure. because < main > tag is important.according to html docs I have read read, it’s better to be like :
<header>-<nav><main>-<main section>--<section 1>---<article>----<header>----<div>--<section 2>---<section 2-1>----<article>-<aside><footer>But such action is not available to do in elementor! because elementor is not allowing too much section nesting ! and another issue is that you must only have 1 < main > on your entire page.
I tried integrating this JS code:
document.addEventListener('DOMContentLoaded', function() {
const elements = document.querySelectorAll('div[data-elementor-id]');
elements.forEach(element => {
const mainElement = document.createElement('main');
// Copier le contenu
mainElement.innerHTML = element.innerHTML;
// Copier les styles en ligne
mainElement.style.cssText = element.style.cssText;
// Copier les classes si nécessaire
mainElement.className = element.className;
// Remplacer la div par main
element.parentNode.replaceChild(mainElement, element);
});
});Also I tried to add this code to functions.php file :
function replace_first_elementor_div_with_main($content) {
$header_pos = strpos($content, '<header');
$footer_pos = strpos($content, '<footer');
if (is_singular() && !is_admin()) {
$pattern = '/<div([^>]+)>/i';
if (preg_match($pattern, $content, $matches, PREG_OFFSET_CAPTURE, $header_pos)) {
$replacement = '<main' . $matches[1][0] . '>';
$content .= '</main>';
$content = preg_replace($pattern, $replacement, $content, 1);
}
}
return $content;
}
add_filter('the_content', 'replace_first_elementor_div_with_main');These two codes were added to replace the <div> tag that contains all of the page’s content with the <main> tag; however, this changes how Elementor functions and does not work with all versions of Elementor.
So what should I do? how can I achieve this?
The page I need help with: [log in to see the link]
The topic ‘elementor main html tag – html structure – seo’ is closed to new replies.