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?
- Using My Own Classes On Wp Unit Tests
- How to modify default controls in WordPress theme customizer
- Is it possible to visually group items on the theme customizer?
- How can I add custom text styles to the visual text editor?
- Displaying icon image for WordPress post formats, is there a cleaner way to do this?
- Custom Blocks as part of a theme
- What is the meaning of WordPress’s recommended css classes and where are they applied?
- Customize how a WordPress theme looks like in the Theme Selector
- Internal Stylesheet in WordPress Theme development
- WooCommerce: multiple input field for multiple product variations
- Combining CSS files into a single cached one
- Redirect to another page using contact form 7? [closed]
- How to i style the elements from the TinyMCE
- Customizer – loading settings/controls/sections/panels based on a id/page id
- Integrate WooCommerce theme with a WordPress theme [closed]
- Widget Option is Missing
- How do you use WordPress for a website that’s not in a blog format?
- Using page-id-{ID} from body_class() in local dev, versus live staging
- Default Text not showing from customizer
- How to change footer or for different kinds of users in wordpress?
- Child Theme header1.php file not overwriting parent theme’s header1.php file
- How do I remove inline style in featured image markup?
- different way to achive stylesheet_url
- How do I use a color from theme options?
- Custom image size vs CSS sizing
- How to have content scroll over background
- WordPress Template Part in iFrame
- Why is my CSS not loading?
- Replace site title with logo when logo is uploaded in customizer using
- How to rotate every letter in a title
- Ideal inline dynamic CSS injection
- How to transfer one domain to another domain without losing theme options (customizer)?
- Theming Using Bootstrap Glyphicons and WordPress Dashicons
- Broken theme, template is missing
- JQuery undefined and Stylesheet loads in bottom along with js files
- Is there a WordPress boolean for “theme_customizer_active()”?
- Having issue with WordPress wp_enqueue_style
- How to make theme configurable
- Extending Twenty Eleven Theme
- How do I use wp_nav_menu?
- How can I wrap all blog posts image with
- theme style is applied on the dhasboard rather than the website
- White screen when attaching css to function.php
- Assign custom classes to the divs inside the loop
- SVG in list-style-image breaks when adding fill
- WordPress theme resource won’t load over VPN
- How to clean up the theme for production?
- Templates without a loop, best practice?
- theme-independent CSS/JS files
- How to style bootstrap container in wordpress theme?
- searchform.php doesn’t work properly
- How to override template files in parent theme?
- Customizer: get_preview_url() inside customize_save_after hook
- How to add custom meta box when you have a custom page template file
- add shortcode support in customizer
- Clearing dummy data before launch
- LESS not working in WordPress [closed]
- How to call a widget in a loop at a specific iteration value?
- Place title (in correct place) above image with opaque background [closed]
- Right procedure when you develop a WP Website for a client
- A post with a clear:both in its css destroy the theme design, and the sidebar is moved to the bottom
- Woocommerce Product attribute not imported with wordpress Importer [closed]
- multiple html/css files for wordpress theme?
- New to WordPress – Read the Codex, Other Docs; Still Confused
- CSS preprocessor file messed up after compiled
- Create theme for mobile phones and tablets only?
- How to add custom page elements to the WYSIWYG editor?
- Using the media library for theme customization
- Customize Option Framework
- Why I obtain different visualization when I run the website on my local machine and on remote server?
- Some doubts about WordPress handle the horizontal main menu visualization
- How to create a WP theme that use BootStrap? [closed]
- Alternatives to handle customizer settings
- Update Specific Key Value in Complex `wp_options` object
- my single.php is mixup on some post for no reason
- Remove/Hide a Widget on a Custom Template
- How to use the _S framework
- header, stylesheet not being read
- Tiny MCE custom styles, and preview in the backend
- How to format the first line of a post differently?
- My contact form – I’ve changed the source code but the changes are not being applied
- .current_page_ancestor broken in Twenty Eleven
- How to custom category template based on category?
- How to use multiple check-box values to work in a function and insert values in database
- How to use Canonical URL meta tag to avoid duplicate content issues with WP home pages
- WordPress Animation Adjustments
- Is there a list of default generated Gutenberg block CSS? Unable to align video blocks
- style variations hurt the editing performance
- How to create a robust and logic class naming system in WordPress theme developing?
- Why nav_menu_css_class doesn’t work with apply_filters?
- How do I change the color of individual page titles in WordPress?
- how to change a static testimonials into dynamic
- 3 Level Menu Navigation (3rd Level not displaying)