You could use the setTimeout()
JavaScript method for that:
function delay() {
id = window.setTimeout(rm, 500);
}
function rm() {
// Remove the notice from the DOM.
var e = document.getElementById("id_of_the_notice");
e.parentElement.removeChild(e);
}
Note:
500
(milliseconds) can be changed.
id_of_the_notice
must be changed
Thanks @henrywright
Where is the best place to put this script?
single/member-header.php
?
You could create a .js file in your child theme which you could use for all of your custom JavaScript. You’d then enqueue it with the following code (which goes into your child theme’s functions.php):
function my_enqueue_scripts() {
wp_enqueue_script( 'my-custom-js', get_stylesheet_directory() . '/js/script.js', array(), '1.0.0', true );
}
add_action( 'wp_enqueue_scripts', 'my_enqueue_scripts' );
Note:
This snippet will enqueue a script called script.js located at child-theme/js/script.js
Alternatively, you could just add the code to your footer.php file, just above the </body>
tag like this:
<script>
// JavaScript goes here.
</script>
What is the 'my-custom-js'
in your script?
From WP codex it’s the $handle var <?php wp_enqueue_script( $handle, $src, $deps, $ver, $in_footer ); ?>
Not sure what it is supposed to be.
It does not seem to relate to anything in your above js.
$handle
is simply a name you give your script. I chose my-custom-js
but feel free to use any string you like. custom-script
or maelga-js
are both suitable alternatives.