Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
  • #1353078

    We have a situation where the owner of the website needs to have an emergency message on each page. Some of the pages are using the WordPress default and others are using the Avia Page Builder. So what we did was added a message to child-theme/page.php which took care of the WordPress default pages. Then we used the heading element to manually add the message to the few pages that are using the Avia page builder. The home page has a different message.

    My question: is there a global message we can add to functions.php or header.php to add this message across all pages except the home page? We want to be able to easily edit the message in one place and remove it when the time comes.


    Hey GWS,
    Thanks for the link to your site, try adding this code to the end of your functions.php file in Appearance ▸ Editor:

    function custom_special_message() { ?>
    window.addEventListener('DOMContentLoaded', function() {
    	if ($("body").hasClass("home")) {
      $( '<div class="av-special-heading">Our training center is currently closed for all in-person classes</div>' ).insertBefore( 'main.content' );
      	 $( '<div class="av-special-heading">Sorry we are currently closed for all in-person classes</div>' ).insertBefore( 'main.content' );
    add_action('wp_footer', 'custom_special_message');

    The first message is for your homepage, the second is for all other pages. You can add a custom class to the div to style to suit your needs.
    In my test I had to inject jQuery, because your site was giving the “jQuery is not defined” error, it looks like “rocket-loader” is adding jQuery too late, at least in my test.
    If you have any trouble with this script try disabling “rocket-loader” or allow jQuery to load in the header, I’m not sure what options the “rocket-loader” gives you.

    Best regards,


    Thank you, Mike. I disabled Rocket Loader and added the script to functions.php and that does the trick. I appreciate your help. You can consider this topic closed.



    Great, I’m glad that Mike could help you out. I’ll close this thread for now then, please open a new thread if you should have any further questions or problems.

    Best regards,

Viewing 4 posts - 1 through 4 (of 4 total)
  • The topic ‘Adding a message in the content on all pages using functions.php’ is closed to new replies.