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
- Go Back to Previous Page
- Why do templates contain so many PHP tag pairs?
- Integrating PHP into Javascript to display map markers with Google API
- Display notification only once
- Using wp_localize_script to store the template url into a variable to use in JS
- Placing raw HTML inside a WordPress shortcode
- Colorbox ajax loading of outside HTML content works perfect on localhost but not on server
- An unwanted inline style is added to my body tag
- Simple Plugin with custom javascript wont work – no console error
- Button not refreshing page
- Transferring working local PHP site to wordpress – with database (MySQL)
- How to inject variables into public-facing JS using wp_enqueue_script
- Ajax random number always the same
- Post repeating with infinite scroll
- How to convert select to HTML with PHP tags inside of it [closed]
- php within html within php
- load ajax using admin-ajax.php
- php esc_html_e with an html link inside not working
- Using ob_start and ob_get_clean with wordpress shortcode
- WordPress wp-admin redirect and exception
- Creating an image from a custom field
- Function Display article [closed]
- How to get the second slug of a page url?
- Load Javascript for a widget WordPress
- custom add note meta box with add button in wordpress
- duplicate posts with ajax load more wordpress
- How to populate a Gutenberg select field SelectControl with option value from PHP array
- Send an e-mail on address with the link with disliked post
- List sub categories and corresponding posts of a parent category
- population category dropdown and sub category onselect
- Run do_shortcode on php template using JS function
- WP Website is shown in HTML
- Trying to add some custom text into WordPress Post title via function.php
- How can i show specific Category List?
- Using Javascript On Page – Header and Footer Now Missing
- Adding extra data to shortcode attributes and pass it to JS with wp_localize_script
- How to Protect a private folder inside uploads folder, if User is not Logged In?
- How do I make comment-reply-button with that takes to comment reply form on click
- Changable favicon
- How to make a parent page for author.php?
- How to load WP_Editor JS files manually (with AJAX)?
- Multisite – Display different header content based on which site is accessed
- html to posts, jpg to featured image, zip file contains jpg and html
- How do you change the tag font size in the repeater-template.php [closed]
- Add title and caption to thumbnail image on mouseover
- How Can I Center the Logo in the Navigation Menu? [closed]
- Dynamic Gallery
- Cannot get custom javascript to execute on page
- HTML in PHP problem [closed]
- How to create and add js and css file when server is not on my PC?
- Object of class WP_Post could not be converted to string while trying to console.log wp_get_nav_menu_items
- Check radio get value to array
- Remove Woocommerce product from cart with ajax/fetch
- hiddenQuestions.find is not a function