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
- Multiple pages on one with different HTML
- How to use the php if statement [closed]
- lazy load comments wordpress on click
- Using a javascript file to access a get posts array
- Add custom HTML to posts page
- Access/update database with jQuery
- Customizer Show/Hide
- Page Reloads Before AJAX Request Finishes
- How to only show page id as body class?
- Shortcode content output but not in correct place
- Ajax return code 400
- Pass PHP variable to JavaScript without inline JS
- Customize Theme comment template to Insert VoteUp and VoteDown buttons
- Input data from email form not going to JSON file
- How to optimize the IF condition with many conditions and same output [closed]
- Show latest posts in a plain HTML website custom widget [closed]
- admin-ajax Firing Error 400 When Logged In
- Hide HTML element (by class or ID) with PHP
- How to remove coupon dropdown feature
- Jquery window.send_to_editor function
- How to add drag and drop functionalities to a div inside option panel
- Add html link in functions.php files of the theme
- PHP contact form not redirecting [closed]
- How to Schedule Cronjobs for start of every month and year
- Handling PHP/HTML inside the output of a shortcode function
- How to change logo by category
- Submitting a form, using Ajax, to run a SQL Select query based on user input from the form
- Need help removing […] after excerpt
- Shortcode displaying at the top of the page [duplicate]
- PHP variables in a post?
- Hot to check if new posts have been published since page load and notify online users?
- Background image no longer fits to screen now that project is in php files
- Unable to display multiple parameters from url by javascript through shortcodes
- Shortcode in Shortcode/HTML Graphics and Pictures
- I have a lot of JavaScript erorrs after SSL someone can help me?
- HTML Formatting “single_term_title()”?
- Show the subcategory name based on current product
- wordpress all post filter by year
- Creating Log-In Page for backend server
- user update profile for custom code
- Vertical Menu for one page only
- A javascript function that simply runs a php function on the plugin
- Display text of price (minus 20%) on every product page in a sentence.
- Populate an array from the loop, and then read the array into JS
- Why isn’t my custom Javascript showing up in my custom template?
- Help with my first Metabox helper class
- nested divs, classes for a grid in loop [duplicate]
- how to manipulate HTML parameters using PHP conditions
- Add multiple JavaScript files to template header [duplicate]
- Trouble figuring out how to get my button to submit comment
- How to edit homepage in WordPress?
- WP_Query not returning results
- How do I link the side images?
- How can I use AJAX in child theme template?