Change button link

  • Hi,
    I want to change my button link when the display width less than 760 to api.whatsapp.com. I checked using console.log it success, but the link doesn’t change.
    I use this code

    <!-- WhatsApp Mobile Detect -->
    	<script>
    		let collection = document.getElementsByClassName("cta_wa");
    		if (window.matchMedia("(max-width: 760px)").matches) {
    			console.log('test hp')
    			collection.url = "https://api.whatsapp.com/";
    		} else {
    			console.log('test web')
    			collection.url = "https://web.whatsapp.com";
    		}
    	</script>
    	<!-- End WhatsApp Mobile Detect -->
  • Hi there,

    The best place to get help with that is to post in the official WordPress.org support forums:

    https://wordpress.org/support/forums/

    The forum you have posted is for the WordPress.com hosting platform, which is different than the WordPress software that your site is using. You can learn more about these differences here:

    WordPress.com vs. WordPress.org

  • The topic ‘Change button link’ is closed to new replies.