None of those functions are JavaScript functions. They’re PHP functions. You need to run them outside the <script>
tag in the PHP:
add_action(
'wp_footer',
function () {
if ( is_archive() || is_category() || is_author() || is_date() ) {
?>
<script>
// etc.
</script>
<?php
}
}
);
You were also missing the ()
on is_archive
.
Related Posts:
- Audio Player not loading when the content is loaded through Ajax, MediaElement.js no applied
- Variation prices breakdown only for single product page
- Is there a way to pull remotely generated XML, process it, and display it on a Managed WordPress page?
- Add Imports to Existing WordPress Import Map
- Go Back to Previous Page
- what is correct way to hook when update post
- Most efficient way to add javascript file to specific post and/or pages?
- WordPress Visual Editor Stripping HTML Changes
- Using register_activation_hook in classes
- WordPress and event-driven programming – what is it about?
- WordPress Admin Bar pushed Sticky Footer off the bottom of the page
- Pass media upload value to input field
- Add a class to links in the visual editor (how to get old dialog back)
- Custom plugin: Trying to show saved data on frontend
- Combine CSS and JS files from plugins
- How to call a PHP function from Javascript in WordPress
- Receiving Stripe Webhooks on a wordpress website
- Remove Woocommerce product link
- How to remove hardcoded characters from playlists?
- Check php version before theme activation
- JqueryUi Dialog giving Uncaught TypeError: this._addClass is not a function error
- WordPress Infinite Scroll without using any plugin
- Gutenberg Blocks doesn’t render correctly when using do_blocks
- Display message once per session to users with a specific role
- Create Image Uploader for Widget
- WordPress Ajax always returns a 404 error
- How to preserve PHP modifications while upgrading WordPress?
- Conditionally loading JavaScript based on the Advanced Custom Fields in the post
- Change the footer text on the login page
- How can I remove “Proudly powered by WordPress” from twentyeleven without modifying footer.php?
- How can I hook into and edit the text of a wp_nav_menu tag?
- How to remove a metabox from menu editor page?
- WooCommerce: How to display item meta data in email confirmation using woocommerce_order_item_meta_end
- WordPress customizer: load controls in a custom div
- Check if page parent has certain template
- Multiple wp_schedule_event cron jobs in plugin cause multi-execution
- How to remove “out of stock” variation options from size dropdown in woocommerce?
- Ajax template: how to handle head section
- Calling a method from functions.php on a click of a button
- Get post meta in enqueued js file
- Is there a reason why my wordpress PHP page isn’t loading into my PHP template
- How to resize image on client-side before upload?
- How to use WordPress (PHP) functions in AngularJS partials files?
- Limit the Excerpt field in WP-Admin in words
- Prevent publish status/date saved on transition_post_status hook
- Run shortcode at certain resolution
- Passing PHP Variables to JS using Localize Script
- Nice scroll to wordpress
- How to create a custom config file and get data using inline JS in a wordpress page
- Where exactly do I write define( ‘WP_DEBUG’, true ) in wp-config file
- How to Remove a Filter from the Admin List Table?
- Integrating PHP into Javascript to display map markers with Google API
- How to use the php if statement [closed]
- lazy load comments wordpress on click
- Data fetch and delete by ajax request
- Handling an Ajax form submit
- Customizer Show/Hide Logo and Site Title
- How to block specific keywords from searching on WordPress?
- Understanding WordPress child theme custom JS loading
- How to create filterable portfolio in WordPress?
- Hooking new functions to actions + passing parameters
- Woocommerce, recognize the loop of related products
- API JSON Data in WordPress
- Find variables available at a given hook
- Passing data between two hooks in separate HTML requests
- Use different javascript files for each page on website
- Is $hook a global variable in WordPress
- Replace existing content from specific WooCommerce admin orders list column
- Using a javascript file to access a get posts array
- Using an Image Slider twice on the same page
- Executing `createimagefrompng()` from save_post hook (or equivalent hook)
- JavaScript, best way to use data from the loop
- Custom WordPress+PHP+MYSQL+AJAX form, submit event not captured by Javascript, but does POST data to the DB
- Javascript code inside “” in core WordPress files .php
- Create custom blocks for bootstrap
- Minify HTML, CSS, JS with PHPWee?
- Run a Parallel PHP Application with WordPress
- Getting my head round WordPress filter
- Click loads template via ajax
- Delete option value from array using update_option()
- Archive dropdown styling not applied
- enqueue hover function
- using woocommerce_template_single_add_to_cart in shop-loop – javascript issues [closed]
- Uncaught TypeError: Cannot read property ‘firstChild’ of null after upgrading to WordPress 5.5
- How To Change The Html of Products filtration sidebar in Woocommerce?
- Display notification only once
- Access/update database with jQuery
- How to display something in a div when the user clicks on a text in another div – no page refresh [closed]
- Use WordPress’s Media Uploader/ Manager in non WordPress php application
- Get/Set wp.customize.previewer.previewUrl
- How to set a custom path, for ajax image upload folder in admin?
- javaScript in section of WP API
- Insert all post IDs in new database table
- admin-ajax.php responding with 0
- Using wp_localize_script to store the template url into a variable to use in JS
- How can the plugin directory path be returned into ?
- 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