php – Add multiple HTML attributes to an Elementor button

Question

I want to add multiple HTML attributes to an Elementor button across all blog posts on my website. The buttons all have links in them, to which I want to add like 3-4 ‘rel’ attribute values. Elementor custom attribute options only allow a single attribute name and value to be added, unless you go Pro. I am just an amateur at coding so I don’t know if the below code is correct. I added this to my functions.php file and it did not throw any syntax errors but it also doesn’t work.

I would like to do this without using any additional plugins. Any help is much appreciated.

add_action('wp_head', 'buttonRel');
function buttonRel() {
  if (is_single ('^\d+$')) { 
    ?>
        <script type="text/javascript">
    document.getElementByClassName("elementor-button-link").setAttribute("rel", "abc1");
    document.getElementByClassName("elementor-button-link").setAttribute("rel", "abc2");
    document.getElementByClassName("elementor-button-link").setAttribute("rel", "abc3");
    document.getElementByClassName("elementor-button-link").setAttribute("rel", "abc4");
        </script>
    <?php
  }
}

0
Kai 2 months 2022-09-28T03:28:55-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse