You might use the wp_head
action,
That is triggered within the section of the user’s template by the wp_head() function.
add_action("wp_head", "hook_js");
function hook_js() {
if(is_home() || is_front_page(){
$output="<script> alert('Page is loading...'); </script>";
echo $output;
}
}
Note that is better to add style and script with the action wp_enqueue_scripts
and then enqueue and register them with their proper functions (wp_register_script
& wp_enqueue_script
)
Related Posts:
- What does l10n.js do in WordPress 3.1? And how do I remove it?
- Any advantage of using wp_scripts and is_IE when enqueuing scripts
- Move all the JS files to the bottom|footer, the right way
- How can I add Javascript in the header of all post pages and only post pages
- Removing auto versioning of JS and loading to header
- how can i send this to wp_head – escape problem
- Put dynamic Javascript in header after doing operations
- Failed to load resource: the server responded with a status of 404 (Not Found)
- What is NODE_ENV and how to use it in Express?
- How to deal with net::ERR_SSL_PROTOCOL_ERROR?
- What is the way of declaring an array in JavaScript?
- How to disable JavaScript in Chrome Developer Tools?
- Reactjs – Form input validation
- What is event bubbling and capturing?
- What is lexical scope?
- Remove element by id
- JavaScript “Uncaught TypeError: object is not a function” associativity question
- Angular: mat-form-field must contain a MatFormFieldControl
- JS – ReferenceError: fetch is not defined
- Check if a variable is a string in JavaScript
- How can I add a key/value pair to a JavaScript object?
- Adding an onclick event to a div element
- Typescript : Property does not exist on type ‘object’
- AngularJS : Factory and Service?
- What’s the difference between console.dir and console.log?
- Use images like checkboxes
- What is the difference between document.location.href and document.location?
- JavaScript error (Uncaught SyntaxError: Unexpected end of input)
- Preloading images with JavaScript
- How to print elements from array with javascript
- What is the JavaScript version of sleep()?
- How do I scroll to an element using JavaScript?
- Finding largest integer in an array in JavaScript
- javascript set cookie with expire time
- Angular: conditional class with *ngClass
- How to properly export an ES6 class in Node 4?
- Uncaught Typeerror: cannot read property ‘innerHTML’ of null
- Sorting HTML table with JavaScript
- Relation between CommonJS, AMD and RequireJS?
- How to loop through an array containing objects and access their properties
- Expected linebreaks to be ‘LF’ but found ‘CRLF’ linebreak-style
- Failed to load resource: net::ERR_CONTENT_LENGTH_MISMATCH
- TypeError: Invalid attempt to spread non-iterable instance
- Declaring multiple variables in JavaScript
- Anagrams finder in javascript
- Validate date in dd/mm/yyyy format using JQuery Validate
- CSS Animation onClick
- Partial render in HTML/JavaScript
- How can I check if a string is a valid number?
- Stopping a JavaScript function when a certain condition is met
- Showing an image from an array of images – Javascript
- Javascript isnull
- Set value to currency in
- How to add 30 minutes to a JavaScript Date object?
- How to execute a function when page has fully loaded?
- Is there a “not in” operator in JavaScript for checking object properties?
- How to add a keyboard listener to my onClick handler?
- SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data
- HTML Entity Decode
- what is ScriptResource.axd in the page load in web app?
- {“error”: “Please use POST request”} – alternative solution to submitting a form
- Get JavaScript object from array of objects by value of property [duplicate]
- Simple pagination in javascript
- Javascript swap array elements
- jQuery sort elements using data id
- Resource interpreted as Document but transferred with MIME type application/zip
- How to redirect to another page using AngularJS?
- events.js: 141 throw er; // Unhandled ‘error’ event
- Default text on input
- JSX not allowed in files with extension ‘ .js’ with eslint-config-airbnb
- Cannot read property ‘preventDefault’ of undefined in javascript error
- Javascript callback function throws error “Callback is not a function” in firefox
- How can I stop the browser back button using JavaScript?
- How to use wordpress default Password Strength Meter script
- wp_enqueue_script() not working at all
- Script to run at completion of Page Loading
- Documentation for IDE’s
- Cloudflare’s Rocket Loader + WordPress -> Ignore scripts?
- Get HTTP response code on non-2xx apiFetch request
- What’s the handle for media.js?
- Add custom HTML markup to Gutenberg RichText
- Enqueue scripts all over but not in single.php
- Multiple media uploader buttons target only one input on the same page
- Adjusting jquery for WordPress
- Enqueue scripts based on browser width?
- in jquery read a multidimensional array via wp_localize_script()
- Custom JS on a specific page
- How to import a JavaScript Library into WordPress
- How to get file object from file_attachment?
- How to change the link address from internal to external
- How do I load urls from an external .js file to my admin head?
- Nothing in dashboard that uses javascript works
- Uncaught TypeError: Cannot read property ‘add’ of undefined bp-plupload.min.js
- Where is the Javascript attribute window._wpCustomHeaderSettings defined?
- How to execute WP shortcode in a javascript string “”
- how to include js in widget?
- JS files landing on page but not working, using childtheme of twentyeleven
- List unused javascript for easy removal
- Replacing & in JS code on pages
- How can I look at/edit what’s being sent to post.php when I hit the publish/update button?