Skip to content

Instantly share code, notes, and snippets.

@chikaibeneme
Created March 14, 2025 15:16
Show Gist options
  • Select an option

  • Save chikaibeneme/b20c143d4986a8fe6e159ac3ff69d53a to your computer and use it in GitHub Desktop.

Select an option

Save chikaibeneme/b20c143d4986a8fe6e159ac3ff69d53a to your computer and use it in GitHub Desktop.
Replace event title heading from <h3> to <h1> on pages with the "page-template-default" class.
function my_swap_event_heading_js() {
?>
<script>
document.addEventListener('DOMContentLoaded', function() {
// Check if the body contains the "page-template-default" class.
if ( document.body.classList.contains('page-template-default') ) {
// Select all event title elements by the specific class.
var titles = document.querySelectorAll('.tribe-events-pro-photo__event-title');
titles.forEach(function(title) {
// If the element is an H3, replace it with an H1.
if ( title.tagName.toLowerCase() === 'h3' ) {
var newHeading = document.createElement('h1');
newHeading.className = title.className;
newHeading.innerHTML = title.innerHTML;
title.parentNode.replaceChild(newHeading, title);
}
});
}
});
</script>
<?php
}
add_action( 'wp_footer', 'my_swap_event_heading_js' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment