Hello @pkrynauw,
Thank you for reaching out,
Where did you add that code? Modifying the core theme’s header.php file is not recommended. Theme updates might overwrite your changes, leading to website malfunctions. Or if we update the header.php file, then you must update it by tracking changes.
However, you can modify this file by copying this file to the child theme.
Instead, you can copy it and place it in the exact path within your child theme. Then, edit that file.
The recommended method for adding custom CSS/JS with custom code is the one I explained in the previous reply. If you want to customize it further, consider contacting a web developer familiar with PHP and WordPress hooks. Customizations are not included in our support policy.
However, if you prefer the standard and recommended way to add your custom CSS/JS in the child theme, follow these instructions:
Using a Child Theme’s functions.php:
1. Install and activate the official child theme from this link: https://github.com/oceanwp/oceanwp-child-theme
2. Access the child theme’s functions.php file. You can use an FTP/SFTP client or your hosting provider’s file manager to navigate to your child theme’s directory and edit the functions.php file.
3. Add Code Snippet, so paste the following code into functions.php, and replacing code:
Method A:
add_action('wp_head', 'my_custom_styles_and_scripts');
function my_custom_styles_and_scripts() {
?>
<style>
/* Your custom CSS code here */
</style>
<script>
// Your custom JavaScript code here
</script>
<?php
}
Method B:
// Enqueue Custom CSS
function my_custom_styles() {
wp_enqueue_style( 'my-custom-style', get_stylesheet_directory_uri() . '/style-custom.css', array(), '1.0.0', 'all' );
}
add_action( 'wp_enqueue_scripts', 'my_custom_styles' );
// Enqueue Custom JS (with optional dependency)
function my_custom_scripts() {
wp_enqueue_script( 'my-custom-script', get_stylesheet_directory_uri() . '/script-custom.js', array('jquery'), '1.0.0', true );
}
add_action( 'wp_enqueue_scripts', 'my_custom_scripts' );
Upload the modified functions.php back to your server.
For more information about adding those codes, please read the links I posted in the previous reply.
Thank you for understanding,
I hope it helps.
Best Regards
-
This reply was modified 6 months ago by Shahin.