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
- 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?