• Hello,

    I am using CometChat on my WordPress MU/BuddyPress site. The chat software works great and is totally integrated with our Buddypress system (avatars show up correctly, video chat works, etc). So far I have integrated the chat software into the main theme by editing the theme files to include it, and I have got it working in the admin dashboard by creating some custom functions that I placed in mu-plugins. Now, I want to make a plugin that will edit both the headers and footers of every theme installed so that the chat software will show up correctly as long as a user is logged into the site. I need to add a link <script> link to jQuery in each themes <head> section, and I need to add the javascript to the footer on each theme, or at least right before </body>.

    Does anyone know how to accomplish this? I’m not exactly sure what I can do in order to make sure it is compatible with each theme. Obviously, each theme I am using should have both a header.php and footer.php as they are standard. I am using WPMU Dev’s Fams 133 pack for themes as well as a few other themes I have picked up here and there.

Viewing 1 replies (of 1 total)
  • Make sure every theme has both the wp_footer() hook in the footer.php and wp_head() hook in the header.php

    Then make your plugin snag those hooks:

    <?php
    /* My CometChat Plugin
    */
    function my_cometchat_footer_script() {
    ?>
    <script type="text/javascript" src="https://my.url.to/cometchat_script.js"></script>
    <?php
    }
    function mu_cometchat_header_script() {
    ?>
    <style type="text/css">
    
    @import url("https://my.url.to/cometchat/style.css");
    
    .img {
    position:absolute;
    left:0px;
    top:0px;
    z-index:1000;
    }
    </style>
    <?php
    }
    
    add_action("wp_footer", "my_cometchat_footer_script");
    add_action("wp_head", "my_cometchat_header_script");
    ?>

    Oh, and if you only want a bit of code to do stuff when a user is logged in then wrap those with something like this:

    <?php if ( is_user_logged_in() ) { ... } ?>

    https://codex.www.ads-software.com/Function_Reference/is_user_logged_in

    Oh, themes that have stacking elements may throw a kink in the works:

    https://www.w3schools.com/css/pr_pos_z-index.asp

Viewing 1 replies (of 1 total)
  • The topic ‘Sitewide Header/Footer Modification’ is closed to new replies.