Executing php on button press

Php is a server-side language. Meaning the code is executed and the user will receive the compiled html code. The only way to execute php code as user is through ‘post’ or ‘get’ requests. So essentially loading a new page. The only workaround is using ajax to load new php code dynamically.

But it may also be that what you plan to do is possible to do with just Javascript. Echoing “pressed” is possible in Javascript using .innerHTML function. Or when you want to show a shortcode-widget on button click you could load it from the beginning and just set it to being visible on button click with Javascript and css.