You can use the functions is_front_page() or is_home() depending on what your home page is.
Also instead of wp_head you can use wp_enqueue_scripts
Your code will look something like this
function add_inline_script() {
if(is_home() || is_front_page)
wp_enqueue_script('js-handler-name', 'js-url');
}
add_action( 'wp_enqueue_scripts', 'add_inline_script');
Related Posts:
- Proper use of Output Buffer
- Does My Child-Theme Functions.php Need if{die} Security In It? [duplicate]
- class=”parent” for wp_list_pages?
- Changing the HTML Of the content
- if has theme mod
- How to override a non pluggable and non hookable function in a WordPress parent theme?
- Count Title and Post Characters
- Remove css styles from specific page
- Custom plugin issue when trying to use the shortcode twice on a page [closed]
- HTML table from shortcode with multiple parameters
- Using PHP to toggle stylesheet and header image, set in cookie
- Show only IF not Google bot [closed]
- How the functions in WP are called in tags
- Differences when using the the_time and the_date functions
- Add a Second Menu to a theme that only support 1 menu
- Custom excerpt function re-factoring
- Add itemprop Schema.org Markup to li Elements in wp_nav_menu
- Using Multiple Submit buttons to trigger customised php functions
- How to get specific image in media library with php
- Displaying the Month and Year that a page was Created?
- Only Show Link If div Exists
- How to access global variable $menu inside a class function
- Change the WP Video Shortcode Output
- How to pick the default selected value in wordpress dropdown?
- Using WP-API and SSE not authenticating user ID
- Validate functions before inserting then into functions.php
- How to retrieve current wordpress profile page URL?
- WooCommerce: How can I get orders with a custom ID in order meta data object?
- Modify function to print tags/categories/exclude tags/categories/ number of posts
- Search not showing all results
- WordPress Quick Question . How to Get Parent Link in Submenu in My Code
- How to Reference/Echo Variable from Another PHP Function
- Detecting classes, adding widgets, and adding divs in with a Nav Walker
- Is the “_s” on this `sprintf(__(‘Page %s’, ‘_s’), max($paged, $page))` just refer to a text domain?
- Exclude category
- How can I make an object available through the entire site?
- WordPress admin-ajax.php
- What exactly do this function declared into functions.php file of a WP theme?
- How do I modify the custom footer text and get theme version number to show in wordpress admin?
- How to use html inside a functions.php code?
- Nested “do” and “add” Actions is possible?
- Display Data in Table from External Database in WP using Shortcodes
- How to check if a Customizer setting is set?
- linking stylesheets and scripts with functions.php
- Show ACF field with link to ultimate member profile/WordPress user profile below the post (single post layout)
- Remove item in Checkout
- How can I hook into the wp_mail function used by BackWPup?
- How to get current post category details inside “loop”?
- Co-Authors Plus: How do I get all authors with a query?
- How to reference PHP in Javascript
- Only load certain artists on this page
- Create special button on WP Tiny MCE Posts Editor for Shortcodes
- Get the alt text of the image in a array
- making php value numeric
- Convert all uploaded PNG files to PNG-8 format
- Make table disappear when fields are left blank?
- How to Redirect Buddypress Directories To Login Page For Non Logged in Users
- Woocommerce order status payment
- How to define a rule in functions.php that ONLY disables the default wp functionality that undesirably changes ‘&’ to ‘#038;’?
- Unzip file in functions.php, and add it to cron
- Add Block Before Entry Title Using PHP
- How to assign page id with array in page_scheduled_event
- Display logged in user name and lastname on page
- How to Add a cutsom slug to my custom author role
- Dynamically populate parameter in Gravity Forms using PHP
- Store ajax data in PHP variable
- comment_post (if comment is approved OR $comment_approved === 1) not working?
- Cannot find the php_ini configuration file to find my error log to see why my code is not working
- How to output the taxonomies that are assigned to each custom post?
- Having trouble creating two shortcodes, one for logged in user and one for visitors
- How can i create a function tag in my plugin
- How to escape echo for input tag?
- Including user data in “new user notification email”
- Display current user metadata on WordPress page
- Reload page with a different shortcode when a user selects from a dropdown
- Refresh page after login with litespeed cache
- Return newly created category by code
- WordPress Ajax filter: Create two loops for different output styles?
- Get Billing Email from WooCommece Checkout and Pass to Fullstory JS
- How to delete specific element when it is not homepage?
- is_user_logged_in() not working in homepage
- Custom Post type Ajax search results
- Customizing the output of the archive and category widget without altering the original behavior of the widget
- How can I include tags in wordpress search without a plugin
- Using catch_that_image() for galleries?
- How to set up an auto delete post?
- Display a post based on its metabox selection
- apply_filters() function
- Get category id for a custom category and display it in a class
- Calling the Next category link on an archive page – WordPress
- Using tag to output text in Genesis?
- Merging two excerpt functions to work with conditions
- wp wp_register_script function results type parameter missing
- php “use” not working in template [closed]
- How to add margin underneath woocommerce total price amount -> productpages
- display php code in header using wp_head()
- Load slideshow.css file only if Slideshow is checked / on
- add if statement to the featured image
- Sorting Problem
- How to add different menu items on different menus?