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.
Related Posts:
- WordPress Ajax always returns a 404 error
- Calling a method from functions.php on a click of a button
- Nice scroll to wordpress
- Javascript code inside “” in core WordPress files .php
- Minify HTML, CSS, JS with PHPWee?
- Slide in Panel WordPress Post
- Show post in slider
- Populate dropdown with Child Pages based on Parent Page chosen
- search and replace preword from author
- How to change redirection route to a php page for making it only accessible by logged-in members?
- parts of url disappear when using # inside href=”” [closed]
- Noscript not working as it should in wordpress site
- Add Codepen animation as Preloader to WordPress
- HTML escaping data with ajax requests
- Override user-edit.php to design own profile page
- Calling PHP Titles inside Javascript Markup
- Link to page with posts of specific type
- Replacing WordPress Icons (menu,icons32, etc)?
- Is it possible to isolate and use WordPress functions outside of wordpress
- Time Delay a URL Redirect for Specific Page
- Cascading dropdown select search based on Parent Page & Child Page
- WordPress cascading dropdown selection search based on Parent Page & Child Page
- Display WordPress search results based on the selected Sub-Category
- html form: redirect page after form completes submit function and posts data
- WordPress User Meta value variable into Google Gauge Chart
- Search bar for wp menu
- Adding HTML Code to Replace Text in PHP
- Add other class content with reference class value
- Using Google Analytics in an enqueued JS file
- separate list of programs in html/javascript coming from php
- How to use wp_ajax_set_post_thumbnail?
- Passing a value from an input field to a php function in WordPress?
- How do I disable cache for a certain page?
- WordPress Slider is not working
- Show subcategory name selected in specific category woocoommerce
- sessionStorage saves input value in browser but it is not loaded in the form field
- Collapsible menu on post sidebar only expands and does not collapse
- Target a specific container to style on WordPress storefront theme
- scroll scrpit to particular button position to next id when click button
- Bootstrap Carousel Indicators Won’t Cycle On Custom WordPress Theme
- Where to find the html for WordPress site? [closed]
- I need help implement a Javascript code into the PHP file
- Trying to customize wordpress drop down categories
- Is there a better way to output HTML as a shortcode?
- Load wp_editor on button click
- Slick slider not working on wordpress
- Is It Possible to Block Redirect Checker Tools from Knowing Where URLs are Redirected?
- How can I add tinymce editor in WordPress with jQuery?
- How to speed up admin-ajax.php in wordpress
- JQuery not working on WordPress Admin page [closed]
- Customizer Show/Hide
- Page Reloads Before AJAX Request Finishes
- Placing raw HTML inside a WordPress shortcode
- How to only show page id as body class?
- Colorbox ajax loading of outside HTML content works perfect on localhost but not on server
- How to make custom total price reactive in navigation
- Adding tawk.to code just before body tag on functions.php file
- How do I fetch all comments per post via WP REST API?
- Deregistering a script in WordPress seems impossible
- Sending jsPDF documents to the server
- Shortcode content output but not in correct place
- How to prevent those PHP variables from being cached on WordPress?
- Ajax return code 400
- Correct syntax to html php conversion
- An unwanted inline style is added to my body tag
- How to properly insert a link to a template in WordPress?
- How can I add an alert (like the old javascript alerts) to my WP page?
- Pass PHP variable to JavaScript without inline JS
- Upload Image in a WordPress page using PHP
- How can I output a php value into a JS file within WordPress?
- Add itemprop Schema.org Markup to li Elements in wp_nav_menu
- Using shipped version of jquery
- Putting PHP variables into javascript [duplicate]
- Removing unneccessary p-tags (Not every p)
- Bridging TinyMCE js and WordPress PHP?
- How can I hide Home in my menu in a specific page?
- WordPress automatically adding html tag around PHP code
- Missing sidebar parameter “fix” – before_content
- Trying to implement Ajax comments in WordPress, getting WP error
- How to test nonce with AJAX – Plugin development
- How do I display a user’s previous orders as a select box option on a product?
- Simple Plugin with custom javascript wont work – no console error
- How Display Posts on category
- How does this WordPress Plugin (Thrive Comments) apply their custom comment sort? [closed]
- How can I use a modal window to display the current post in loops featured image?
- How to get the POST TITLE using the POST ID?
- js file in root loading without
- class click counter save number
- HTML tags in bloginfo description
- Trigger popup in a php if/else statement
- ACF page while loop breaks footer while loop
- Slider loading issue
- Getting a specific post values to another div or modal
- AJAX request status 200 but no actual “response”
- Button not refreshing page
- Add a class to the anchor tag on HTML5 gallery
- Transferring working local PHP site to wordpress – with database (MySQL)
- Ajax not working es expected (Returns 0)
- Use menu link or onClick to set a variable
- how to remove metadata from the posts of my blog?