Actually you shouldn’t add JS and CSS files to your header.php
, but make use of the functions wp_enqueue_script()
and wp_enqueue_style()
to add them there.
Example taken from the codex page:
/**
* Proper way to enqueue scripts and styles
*/
function theme_name_scripts() {
wp_enqueue_style( 'style-name', get_stylesheet_uri() );
wp_enqueue_script( 'script-name', get_template_directory_uri() . '/js/example.js', array(), '1.0.0', true );
}
add_action( 'wp_enqueue_scripts', 'theme_name_scripts' );
Related Posts:
- use add_action(‘wp_head’) in a widget for generating dynamic CSS styles
- First completely customized theme, where should I start?
- Modify the Additional CSS section (adding a disclaimer)
- CSS added through customizer neglects the need of a child theme?
- Can’t change theme name
- WordPress 3.5 + Foundation 5 not working on IE9
- How customizable is a self-hosted WordPress blog compared to a Blogger blog?
- How to define and link full path to css located at a random folder on header.php
- Do I actually need to link my theme’s style.css in the theme files
- Why is wp_head() creating a top margin at the top of my theme header?
- CSS classes for theme
- What are the ADVANTAGES of ORIGINAL wordpress template structure?
- Splitting WordPress theme CSS into multiple files, good or bad?
- Best practices – Should I create a child theme vs. customizing a framework theme? (such as HTML5 reset)
- How to disable 3.1 “Admin Bar” via script for the admin user?
- Suggestions for creative use of post format feature, or themes that use them well
- Add class to before_widget for all widgets with a dropdown and a counter
- What is the best practice for customizing a plugin’s JavaScript/jQuery?
- Why max-width:97.5% on content images?
- why does twenty eleven theme mix up the css measurement units?
- Setting up partial Right-to-Left admin interface
- How the WordPress sidebar works
- Should we localize custom-made themes / plugins?
- Extend walker – navigation, adding data attribute to a tag
- How can I remove the Static Front Page option from the Customizer
- Set front page as static page [closed]
- How to programmatically bring back “excerpts” field in post editor in WP 3.1+
- How can i customize the comment list
- Move my theme style.css into a folder
- How to keep theme layout the same when admin gray bar is present?
- Enqueued Stylesheets Effecting Admin Styles
- Theme Customizer not loading
- How to retrieve an image from a post and display it before excerpt of a post? [duplicate]
- Best practices: Custom theme sidebar menu – hardcode or widget?
- WordPress 5.8 update problem custom theme styles are overridden by core styles common.min.css
- Customizer API and add_panel(). Panel doesn’t show
- Where is definied the theme location for the main menu in a WordPress template?
- How to correctly add JQuery in a WP theme?
- Is it necessary to prefix every css class in a theme framework?
- current-menu-item class not working
- What is the best way to handle multiple calls to get_template_directory_uri() and similar functions?
- Weekly background code not working
- Displaying theme options in css
- Removing non native customizer settings from a child theme
- How to reorganize the items returned by wp_list_comments()?
- How do the default themes reference style.css?
- which is the best way to customize nav-menu-template.php?
- Multiple Page Templates & CSS
- How do I Add images uploaded in the post to a default custom field
- How to add a button which saves the post then executes a function
- Limitations when modifying wp_title with a filter
- How to edit theme functions file to modify pagination?
- Font Awesome 5 Free – far working but fas is not? [closed]
- “Add A Widget” button in the Customizer
- Q: How to pull data from custom table to populate zustomizer setting/control select options
- How remove render blocking css from wordpress when you build a theme?
- Move default page templates to sub directory
- How to get javascript slider to work! [closed]
- How to modify default controls in WordPress theme customizer
- WooCommerce: multiple input field for multiple product variations
- Redirect to another page using contact form 7? [closed]
- Integrate WooCommerce theme with a WordPress theme [closed]
- How do you use WordPress for a website that’s not in a blog format?
- Child Theme header1.php file not overwriting parent theme’s header1.php file
- Replace site title with logo when logo is uploaded in customizer using
- How to rotate every letter in a title
- Theming Using Bootstrap Glyphicons and WordPress Dashicons
- Broken theme, template is missing
- Having issue with WordPress wp_enqueue_style
- theme-independent CSS/JS files
- How to style bootstrap container in wordpress theme?
- searchform.php doesn’t work properly
- Customizer: get_preview_url() inside customize_save_after hook
- How to add custom meta box when you have a custom page template file
- Place title (in correct place) above image with opaque background [closed]
- Right procedure when you develop a WP Website for a client
- New to WordPress – Read the Codex, Other Docs; Still Confused
- CSS preprocessor file messed up after compiled
- How to add custom page elements to the WYSIWYG editor?
- Customize Option Framework
- Why I obtain different visualization when I run the website on my local machine and on remote server?
- my single.php is mixup on some post for no reason
- How to format the first line of a post differently?
- How to custom category template based on category?
- style variations hurt the editing performance
- how to change a static testimonials into dynamic
- 3 Level Menu Navigation (3rd Level not displaying)
- overlay post title over post’s featured image
- Change site title color on individual pages
- How to fix an issue with customizer live preview?
- Any way to permanently translate themes?
- How to share posts (and plugins) between existing site and new, separate dev/test installation?
- Custom CSS no getting applied
- Enqueue Stylesheets After Theme’s “rtl.css”
- Why the slideshow is not shown in my theme?
- Any disadvandages if I style the wordpress align classes without img and .wp-caption prefix
- How to output wp_enqueue_style() in HTML head instead of footer
- What is The Best Way to Make Parallax header effect for wordpress theme ?? pure CSS or using JavaScript? [closed]
- Permalinks problem with custom theme
- How to split the site’s layout without damaging this layout? [closed]