I've written a javacript and html/css for an element for my main page. I already tried putting my js file into root and "including" it in my header. I've used gutenberg to design my page and i want to add this element to it. can any body help me? its bunch of js and jquery codes and css for style and flexbox html. I have .js .css and .html files on my pc and my site is on localhost. my themes is Astra free version.
The proper way would be for you to:
You do this to be able to continue updating Astra and not loose your custom work
add_action( 'wp_enqueue_scripts', 'amir_astra_scripts' );
function amir_astra_scripts(){
wp_register_style(
'amir-styles', // Idendtifier to later enqueue it
get_stylesheet_directory_uri() . 'path/to/file/your-css.css', //full URL to the file
true,
filemtime( get_stylesheet_directory() . 'path/to/file/your-css.css' ), // A dynamic version to bust caching
'all'
);
wp_enqueue_style('amir-styles');
wp_register_script(
'amir-script',
get_stylesheet_directory_uri() . 'path/to/file/your-js.js',
['jquery'], // Make script a dependency of jquery
filemtime( get_stylesheet_directory() . 'path/to/file/your-js.js'),
true // Load in footer instead of header
);
wp_enqueue_script('amir-script');
}
if( is_single() ){
wp_enqueue_style('amir-styles');
wp_enqueue_script('amir-script');
}
If you needed them only on the page with slug "contact" you would do
if( is_page('contact') ){
wp_enqueue_style('amir-styles');
wp_enqueue_script('amir-script');
}