Mnia Mnia - 2 months ago 14
jQuery Question

Replace h1 to h2 using Jquery in Wordpress

I m using custom js and css plugin to change the h1 to h2 on a particular page.Here are my codes but it's not working .I have included the external google link in the header.php

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js">




<script type="text/javascript">
$(function () {
$('.fancy-title h1').replaceWith(function () {
return "<h2>" + $(this).text() + "</h2>";
});
});

</script>





enter image description here

Answer

It should be $('h1.fancy-title') as you are looking for an <h1> tag with class fancy-title according to your html.

https://jsfiddle.net/zvpwwvd3/