Javascript按钮href注入

I made a poor decision early in the process of building a Wordpress website, and in doing so, made my job very tedious to fix it.

Basically, I populated a site with over 1300 pages, and on about 800 of them are a button that doesn't link to anything, and Its on a WYSIWYG editor, so its literally unique for every page. The bright side? They all share the same classes. So I was thinking I could target the classes inside of the a tag associated with the button, and this is what I got:

<script>
document.getElementByClassName('et_pb_button et_pb_button_0 et_pb_module et_pb_bg_layout_light').href = "www.example.org/contact/";
</script>

I've placed this into the footer.php file in effort for it to be run on every page, but it does not seem to be working. Did I miss anything here?

I'm not opposed to other solutions involving php or JQuery, I just need this button to link to a page, rather than a stray #.

WYSIWYG editors will save this button in a specific way. I would recommend to not put a script on every page, but just create a small php script that will query your database, and update the value with the magic of a sql query.

Create a connection to your database. Select the appropriate rows from the database. Find a regex that matches the button, then use preg_replace(..) to replace that button with the working button. Make sure that the regex does not match afterwards. Update the value, then continue.

If the script times out, you can run it again, because the regex no longer matches on the buttons that you already changed.

It's a bit of a dirty fix, but much easier than manually editting all those pages, and much cleaner than running a script on every page just because you made an error.

You can try to adding attribute like

$('.et_pb_button.et_pb_button_0.et_pb_module.et_pb_bg_layout_light').attr("href", "www.example.org/contact/");