Hardcoding scripts in header.php is a very very bad practice. You should always use proper hooks to enqueue scripts and styles in header. This code will give you some idea on how to do this in proper way.
function wpse206834_enqueue_scripts() {
if ( is_author() // Checks if Author Archive is Being Displayed
|| is_category() // Checks if Category Archive is being displayed
)
{
wp_register_script( 'charts', 'SITE_URL/charts.js', array('jquery') );
wp_enqueue_script( 'charts' );
}
}
add_action( 'wp_enqueue_scripts', 'wpse206834_enqueue_scripts' );
Here are some good reads to get started:
Related Posts:
- WordPress API Menu/Submenu Order
- What is the difference between wp_register_sidebar_widget and register_widget?
- How to enqueue script if widget is displayed on page?
- Form Submitting Error with get_template_part()
- Get 10 posts from a WP_Query. If less than 10, get the remainder from elsewhere
- get_stylesheet_directory() returns wrong URI… localhost/using vhosts
- Can’t get staging site to display same way as live site. Completely stumped
- How Do I Programmatically Force Custom Permalinks with My Theme?
- how to test a theme upgrade
- Best practice (forward compatibility) for theme options
- How to use Plupload in themes
- How to add paging to query
- what’s meaning of it when submit a theme?
- How to Modify a Widgets UL and/or LI Classes
- How to remove menus section from WordPress theme customizer
- Returning Variables back into a template
- How to handle thumbnails
- WordPress Google Maps in Custom Theme
- How to add custom template tag in wordpress theme?
- Doubled titles when using All in One SEO with custom template
- In theme development, are there functions which write HTML in a standard fashion to reduce “spaghetti code”?
- Checking if there is an Image inserted – if not don’t display anything
- What page should I use for a contact form?
- Get attachments by user
- Retrieve data using wpdb to use for customizer controls
- Appending a value to metabox before and after saving
- Modify the Additional CSS section (adding a disclaimer)
- I made a my own theme to WordPress and Admin Menu missing from frontend
- Creating directory and file using native wordpress file system
- Don’t understand why theming is so strange and twisted [closed]
- Create self-populating menu and add extra divs to the menu layout
- I want edit_post_link() to open in a new window/tab (target=”_blank”)
- wp_get_attachment_image_src() width and height boolean
- How to remove a file included in parent theme with locate_template() via child theme?
- Can’t override template file in child theme
- How to store functions in… functions.php?
- Simple way to get two language WP site
- get_page_template returning nothing
- How can i initialize a widgetized sidebar (with widgets)
- How do you force a sidebar widget to have a container div around all child widgets?
- Add widgets to available widgets section without changing the theme?
- jQuery not available to other scripts
- Override template file i subfolders
- Does the switch_theme action run when you’re upgrading a theme?
- How to obtain the html stripped version of $category->description?
- How to make animated intro?
- Replace custom logo with text
- StoreFront product pages: Turn the Short Description section into a kindred tab section [closed]
- How to jump to newly posted comment anchor after submit?
- WordPress get_template_part() function not working
- Best way to develop a new theme on a live site, with new content? [closed]
- Tag Page Not Listing All Posts With Tag
- How do I make the most minimal vanilla theme possible with nothing but raw content?
- Pagination not working on page template
- How can I prevent posts with no title showing up in my query?
- How can I wrap all blog posts image with
- Wordpres core-update theme renames theme folder name
- Redux Setting on custom created admin page
- Issue when posting updates/changes to wordress
- Shortcode IF statment help
- WordPress Load Only Page Text
- Bootstrap grid system is not working in my WordPress theme
- Never actually adding the action? Or do I have to call the action?
- How to hide custom sidebar on mobile
- Tiny MCE custom styles, and preview in the backend
- How can I remove image taxonomy pages from my theme and from Google?
- How can I get dynamic content on my static home page
- Creating an option for writing a post without an author attribution for a group blog on WordPress
- WordPress custom menu can’t show 3. level submenu
- How can I add a field for featured image on backend of a custom Taxonomy?
- Social-Link block not loading html on page with custom theme
- add page items to index
- WordPress theme settings not saving
- Custom Static Page to Display Blog Posts in Excerpt Non-Singular Form (is_singular not working?)
- What is difference between add_theme_support and Theme Customization API?
- Alternative solution for script_loader_tag?
- Change logo url by category and in some pages
- Enqueue script for development purposes only?
- How to show Custom Field Value in Woocommerce Shop Page
- Why does the theme of secondary site load the primary one in WordPress Multisite? [closed]
- Creating a Sub Category Template
- Find callback function of custom meta box
- style.css not being rendered in browser
- “Add media” dialog is not showing any images
- How to debug theme (Theme is causing pages to have no style or HTML section)
- How to override wordpress native options with theme options
- Best way to access variables in template markup
- How do I get my theme scripts to load in a custom theme built from Bootstrap
- Problem with multiple menus in theme
- How to convert that page to a wordpress template? [closed]
- JQuery Equal Height in Rows Conflicts Only Works without Registering wp_footer();
- Saving Permalinks Results in 403 MAMP (Windows)
- Add rel to all images in a post
- WordPress theme Modifications not showing up on live server
- Incorrect sidebar showing on WooCommerce Store page [closed]
- Which function(s) to build a paged HTML table
- white spaces on the all sides [closed]
- How to show associated fields if checkbox is checked in customize widget screen using wp_customize?
- When trying to run build script with gutenberg (with SVG import) – Error: Plugin name should be specified
- I am using update_option function to update theme options programatically but page needs to be refreshed many time for changes to reflect!