How to call function in WordPress on button click?

Question

I am new in WordPress plugin development. how can I call to function on button click with wordPRess shortcode?

<?php
/**
 * 
 *Plugin Name: Testing
 *Description:
 **/
 
 function showMessage(){
     echo '<script>alert("Welcome to custom plugin") </script>'; 
 }
  function callFun(){
      
      $button1 = "<button type='button' onclick='showMessage()'>Click to Alert</button>";
      
      return $button1;
  }
  add_shortcode('example','callFun');
?>
0
Saad Abbasi 2 months 0 Answers 10 views 0

Leave an answer