Just make sure that all JS is inside the <script> tags and you can use PHP anywhere as long as it’s .php file and it’s inside the <?php and ?>. Simple as that!
It’s kind of ugly and it’s far from super readable but that’s the way to do it.
<?php
$php_code="My PHP is here!!";
/*Close PHP*/ ?>
<script> //All JS inside the <script> tags
var jsCode="All my JavaScript here!!";
<?php
if( $i_can_also_use_php_here ) { ?>
var jsAgain = 'Just JS and PHP back and forth!!'; <?php
} ?> // "}" is closing PHP if statement
</script>
<?php //Open PHP, no more JS, <script> tag is closed
$continue_php = 'Let's continue this beast!!'; ?>
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
- Executing php on button press
- 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]
- 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
- Pass media upload value to input field
- Blank on static home page?
- How to use a frontend URL with a Plugin
- How to display a value from a radio button in the options menu in wordpress
- Custom image upload
- How to display recent posts on home page with custom HTML
- Upload Image in a WordPress page using PHP
- Using shipped version of jquery
- Trying to implement Ajax comments in WordPress, getting WP error
- Ajax – Call to undefined function get_option()
- Why the JavaScript code is ignored from wp editor?
- JS file work only in index page
- Integrating PHP into Javascript to display map markers with Google API – problem with wp_localize
- Why Won’t My Inputs in a form with a Get method work together?
- How to pass Select value from Javascript to PHP to generate select option on change
- How to get the value of input hidden html from text editor to custom page template?
- How does wp_enqueue_scripts work?
- WordPress Scripts Being Loaded in Footer
- How do I add a custom css to all posts without affecting homepage css? [closed]
- PHP echo inside javascript
- Wrapping a Sidebar within
- How to add API security keys into JS of wordpress securely
- How to edit HTML of my website on WordPress? [closed]
- Get related product based on subcategory selected from category id with ID 142
- wp_nav_menu not working correctly in my underscores theme
- How to add post meta in while loop?
- Adding function to child theme’s function.php
- Hook on file upload
- Using Ajax to submit a form, and run a SQL Select query based on user input from the form
- PHP function for horizontal Woocommerce thumbnails and badges
- How to call my PHP function with AJAX ? wp_query
- Create a WordPress Contact Form to call a POST AWS API Gateway and send user data
- Admin-ajax.php 404 error
- Drop down question
- How to create a php page to collect information from a html page
- Default Image not showing up in Customizer for WP_Customize_Cropped_Image_Control
- How to create a radio button to alt between settings in wp_options table
- customizer live preview layout picker
- Can’t make product images clickable
- Add extra markup to WP menus
- How to style this wp_list_pages markup
- Require Credits Footer
- Can you not edit the HTML and PHP of your WordPress without paying?
- Adding jquery using php function
- How to hide .js files on wordpress website using php or wp plugins or any? [closed]
- notify users when changed database
- Add topbar to static html page
- Weird Javascript:void(0) code in my website
- Why do I get a 404 error on my custom post type archive pagination?
- change div text and link for logged in users
- Font Awesome Icons as squares [closed]
- Editing stylehseet url in head section of WordPress
- How can we upload custom page files?
- Registered a REST Route but I’m Getting a 400 Bad Request