Where the install code goes in .php files, shared footers, Laravel, CodeIgniter, Symfony and WordPress themes, and the mistakes that stop it working.
The short answer
The install code is plain HTML, not PHP. Paste it outside any <?php … ?> block, on the line just above </body>, in the file that prints the bottom of every page. On most PHP sites that's a shared footer file, such as footer.php.
Copy your own code from Administration › Chat Widget › Install: it has your site's ID in place of YOUR-SITE-ID.
Find the right file
Look at the bottom of one of your pages, such as index.php. You'll see one of two things:
A line that includes another file, like <?php include 'footer.php'; ?> or require_once 'inc/footer.php';. Open that file and paste the code above </body> there. Every page that includes it gets the chat.
</body> itself. Each page has its own ending, so the code goes into each page. See pages without a shared footer for a tidier way.
Not sure? Search your whole project for </body> (in VS Code: Ctrl+Shift+F, or ⌘+Shift+F on a Mac). The files it finds are the ones that end your pages.
Pages without a shared footer
Put the code in a small file of its own, then include that file on every page. Next time you only change one file.
Create chat.php next to your pages, with just your install code in it:
On every page, include it on the line above </body>:
index.php, about.php, contact.php …
<?php include __DIR__ . '/chat.php'; ?>
</body>
</html>
If your pages are in different folders, use the path from each page to chat.php, for example __DIR__ . '/../chat.php'.
When the page ends inside PHP code
Some sites print their HTML from PHP, so </body> sits inside echo. Then print the code with echo too, in single quotes, because the code itself uses double quotes:
Or close PHP, paste the code as it is, and open PHP again:
PHP
<?php
// … your code …
?>
<script src="https://chat.quarito.com/l/YOUR-SITE-ID.js" async></script>
<?php
// … your code carries on …
Mistakes that stop it working
“Parse error: syntax error, unexpected '<'”. The code was pasted inside a <?php … ?> block. Move it outside, or print it with echo as shown above.
A syntax error after adding echo. The code was wrapped in double quotes, which clash with the quotes inside it. Use single quotes.
“Cannot modify header information – headers already sent”. The code was pasted at the top of a file, before session_start(), header() or setcookie() run. Move it to the bottom, above </body>.
The chat shows only on the home page. It was pasted into index.php alone. Put it in the shared footer, or include chat.php on every page.
An AJAX call or API stops working. The code went into a file that also sends JSON or other data. Keep it in files that print whole HTML pages only.
Some pages have no chat. Those pages stop early (with exit or die) or use a different layout, so they never reach the footer. Include the code there too.
The change doesn't show. A cache still serves the old page: clear your host's cache, Cloudflare or any caching plugin, and reload.
Testing on your own computer
The chat works on localhost too, for example with XAMPP, MAMP or php -S. Two things to know:
Verify installation can't reach your computer, so it says it couldn't reach the site. That's expected: open your local page and look for the chat button instead.
If you've filled in “Allowed websites” (Chat Widget › Behavior), add localhost to it while you test, or the chat won't show there.
Laravel
Paste the code above </body> in your main layout, usually resources/views/layouts/app.blade.php. Every page that extends the layout gets the chat.
Paste the code above </body> in your shared footer view: app/Views/templates/footer.php in CodeIgniter 4, or application/views/templates/footer.php in CodeIgniter 3. If you use a layout view instead, put it there.
Symfony (Twig)
Paste the code above </body> in templates/base.html.twig, outside any {% block %} that child templates replace.
WordPress theme files
A plugin like WPCode is the safest way (see How to add live chat to WordPress). If you'd rather add it to your theme, use a child theme, so a theme update doesn't remove it, and add this to its functions.php:
functions.php
// The Quarito live chat, at the bottom of every page
add_action( 'wp_footer', function () {
echo '<script src="https://chat.quarito.com/l/YOUR-SITE-ID.js" async></script>';
} );
Or paste the code above </body> in the child theme's footer.php.
Show signed-in customers in the chat
If customers log in to your site, the chat can tell your team who they are. Your server signs their email with your secret key, and the details go on the install code. The key is in Administration › Settings › JavaScript API; keep it on the server, never in the page.