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
- Go Back to Previous Page
- Most efficient way to add javascript file to specific post and/or pages?
- Multiple wp_schedule_event cron jobs in plugin cause multi-execution
- 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
- Find variables available at a given hook
- Passing data between two hooks in separate HTML requests
- JavaScript, best way to use data from the loop
- enqueue hover function
- Display notification only once
- Access/update database with jQuery
- Using wp_localize_script to store the template url into a variable to use in JS
- How can I add tinymce editor in WordPress with jQuery?
- Colorbox ajax loading of outside HTML content works perfect on localhost but not on server
- Pass PHP variable to JavaScript without inline JS
- Simple Plugin with custom javascript wont work – no console error
- Button not refreshing page
- WP functions in .js
- How to prevent XSS alter custom global javascript object & methods in WordPress
- How to inject variables into public-facing JS using wp_enqueue_script
- Customize Theme comment template to Insert VoteUp and VoteDown buttons
- Ajax random number always the same
- Reload part of checkout on changed shipping method
- Javascript file is not working on single.php wordpress [closed]
- Remove a div from RSS feed
- Set meta field to publish date + 2 weeks
- WordPress Gravatar filter is removing my custom attributes
- How to send Ajax request from my plugin in admin dashboard?
- Customizer: Multiple CSS styles on same element in Live Preview
- How to register javascript variables in wp_localize_script?
- AJAX success response is not working but it’s saving my changes
- Are all hooks/functions tied to Kses meant for sanitization?
- Post repeating with infinite scroll
- WordPress Ajax Call inserting data but success response false
- How to optimize the IF condition with many conditions and same output [closed]
- How to remove woocommerce_breadcrumb() from do_action( ‘woocommerce_before_main_content’ ); [closed]
- Should `wp_login` be used since it’s deprecated?
- Is the wp_enqueue method efficient?
- Omit custom post type from wp-sitemap.xml based on meta key using wp_sitemaps_posts_query_args
- admin-ajax Firing Error 400 When Logged In
- How to use a custom hook
- Making an AJAX call to refresh a table
- add onchange to select in a wp form
- Jquery window.send_to_editor function
- Theme not calling Jquery properly
- Get access to variable from previous pageview, excluding ajax-calls
- WordPress redirect redirecting too many times or not at all
- How to have different site identity logos on each page on Astra Theme [closed]
- Post repeated when opening in overlay, how do I solve this? [closed]
- How to change logo by category
- Submitting a form, using Ajax, to run a SQL Select query based on user input from the form
- Comapare get_user_meta value
- Is it possible to isolate and use WordPress functions outside of wordpress
- Testing a Form’s Zipcode Field with Regular Expressions to Determine WordPress Page Behaviour
- security concerns if using html data-* attribute for l10n?
- Replace a single variable with add_filter
- Removing “There is no account with that username or email address.” error message in “/wp-login.php?action=lostpassword”
- Prevent header and footer from loading on specific pages with template or plugin
- Search bar for wp menu
- Executing php on button press
- Contain multiple page templates in one PHP custom template file in WordPress?
- Run do_shortcode on php template using JS function
- Trouble Accessing Gravity Forms API (GFAPI)
- 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
- How do I get the value of a current user’s custom field?
- Adding extra data to shortcode attributes and pass it to JS with wp_localize_script
- Need to forward Data from WooCommerce Webhook sent to same site WordPress REST API custom endpoint
- Show the subcategory name based on current product
- Cannot successfully execute AJAX script to call function.php specific function. Using XAMPP localhost to test
- sessionStorage saves input value in browser but it is not loaded in the form field
- Replacing entire tag with shortcode – JavaScript [duplicate]
- How do I make comment-reply-button with that takes to comment reply form on click
- wordpress all post filter by year
- Fatal error when using array_diff() function inside of wp_update_nav_menu hook?
- How to load WP_Editor JS files manually (with AJAX)?
- Bootstrap Carousel Indicators Won’t Cycle On Custom WordPress Theme
- Where to find the html for WordPress site? [closed]
- Why isn’t my custom Javascript showing up in my custom template?
- 500 (Internal Server Error) of external php file
- Add title and caption to thumbnail image on mouseover
- Problems with plugin that fetches data from database with ajax
- Dynamic Gallery
- Cannot get custom javascript to execute on page
- Cannot modify header information – headers already sent
- 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
- Pass a PHP variable (loop-audio.php) to jQuery function (js/script.js)
- Send a custom notification to customer on WooCommerce cancelled order status
- bloginfo url in javascript
- Fetching only specific value from php file
- transition_post_status hook, works – but not if the post is new
- Guests comment form – prevent duplicate email addresses
- Woocommerce – add tracking code to another email template