Stammer AI WordPress Chatbot Plugin

WordPress Plugin For Stammer AI — Download 📥

Addison Best
5 min readJul 22, 2024

Stammer AI is a SAAS company built for AI Agencies. They make it super easy to add AI Chatbots to any website.

These Chatbots are built for agencies — you can completely white-label the chatbots and start your own AI Chatbot agency.

Stammer AI Wordpress Chatbot Plugin
Stammer AI WordPress Chatbot Plugin

You can try a working example of an AI chatbot on my website aigrowthguys.com

Screenshot of AI Chatbot

Stammer AI offers an embed code to install the Chatbot on any website.

Embed Code for Stammer

I use WordPress for many of my websites.

To make it easier to install the Chatbot and control it — I decided to make a simple WordPress Plugin for Stammer.

You can embed the code in Your WordPress admin with this plugin and your AI Chatbot will show up immediately — with no additional coding.

You can also control which pages you want to see the Chatbot on — and you can embed the AI Chatbot within any WordPress Page or Post with a short code.

Stammer AI WordPress Chatbot Plugin

<?php
/*
Plugin Name: Stammer AI Chatbot Plugin
Description: A plugin to display a chat bubble on all pages by default, with options to disable on specific pages, and admin settings to manage the chat script and toggle site-wide display.
Version: 1.0
Author: AI Growth Guys
Author URI: https://aigrowthguys.com
*/

// Add the admin menu
function stammer_ai_chatbot_admin_menu() {
add_options_page(
'Stammer AI Chatbot Settings',
'Stammer AI Chatbot',
'manage_options',
'stammer-ai-chatbot-settings',
'stammer_ai_chatbot_settings_page'
);
}
add_action('admin_menu', 'stammer_ai_chatbot_admin_menu');

// Display the settings page
function stammer_ai_chatbot_settings_page() {
?>
<div class="wrap">
<h1>Stammer AI Chatbot Settings</h1>
<p><strong>Stammer AI</strong> requires an account at <a href="https://stammer.ai/?via=andrew" target="_blank">Stammer AI</a>.</p>
<form method="post" action="options.php">
<?php
settings_fields('stammer_ai_chatbot_settings_group');
do_settings_sections('stammer-ai-chatbot-settings');
submit_button();
?>
</form>
</div>
<?php
}

// Register settings
function stammer_ai_chatbot_register_settings() {
register_setting('stammer_ai_chatbot_settings_group', 'stammer_ai_chatbot_script');
register_setting('stammer_ai_chatbot_settings_group', 'stammer_ai_chatbot_sitewide');
register_setting('stammer_ai_chatbot_settings_group', 'stammer_ai_chatbot_embed_code');
add_settings_section('stammer_ai_chatbot_settings_section', '', null, 'stammer-ai-chatbot-settings');
add_settings_field('stammer_ai_chatbot_script', 'Chat Bubble Script', 'stammer_ai_chatbot_script_callback', 'stammer-ai-chatbot-settings', 'stammer_ai_chatbot_settings_section');
add_settings_field('stammer_ai_chatbot_sitewide', 'Enable Chat Bubble Sitewide', 'stammer_ai_chatbot_sitewide_callback', 'stammer-ai-chatbot-settings', 'stammer_ai_chatbot_settings_section');
add_settings_field('stammer_ai_chatbot_embed_code', 'Embed Code for Shortcode', 'stammer_ai_chatbot_embed_code_callback', 'stammer-ai-chatbot-settings', 'stammer_ai_chatbot_settings_section');
}
add_action('admin_init', 'stammer_ai_chatbot_register_settings');

// Callback for script input
function stammer_ai_chatbot_script_callback() {
$value = esc_attr(get_option('stammer_ai_chatbot_script', ''));
echo '<textarea name="stammer_ai_chatbot_script" rows="5" cols="50" class="large-text">' . $value . '</textarea>';
}

// Callback for sitewide toggle
function stammer_ai_chatbot_sitewide_callback() {
$value = get_option('stammer_ai_chatbot_sitewide', '1');
echo '<input type="checkbox" name="stammer_ai_chatbot_sitewide" value="1"' . checked(1, $value, false) . ' />';
}

// Callback for embed code input
function stammer_ai_chatbot_embed_code_callback() {
$value = esc_attr(get_option('stammer_ai_chatbot_embed_code', ''));
echo '<textarea name="stammer_ai_chatbot_embed_code" rows="5" cols="50" class="large-text">' . $value . '</textarea>';
}

// Add the meta box to the post/page edit screen
function stammer_ai_chatbot_add_meta_box() {
add_meta_box(
'stammer_ai_chatbot_meta_box',
'Chat Bubble Settings',
'stammer_ai_chatbot_meta_box_callback',
['post', 'page'],
'side'
);
}
add_action('add_meta_boxes', 'stammer_ai_chatbot_add_meta_box');

// Display the meta box
function stammer_ai_chatbot_meta_box_callback($post) {
wp_nonce_field('stammer_ai_chatbot_save_meta_box_data', 'stammer_ai_chatbot_meta_box_nonce');
$value = get_post_meta($post->ID, '_stammer_ai_chatbot_disable', true);
?>
<label for="stammer_ai_chatbot_disable">
<input type="checkbox" name="stammer_ai_chatbot_disable" id="stammer_ai_chatbot_disable" <?php checked($value, '1'); ?> />
Disable Chat Bubble
</label>
<?php
}

// Save the meta box data
function stammer_ai_chatbot_save_meta_box_data($post_id) {
if (!isset($_POST['stammer_ai_chatbot_meta_box_nonce'])) {
return;
}
if (!wp_verify_nonce($_POST['stammer_ai_chatbot_meta_box_nonce'], 'stammer_ai_chatbot_save_meta_box_data')) {
return;
}
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
return;
}
if (!current_user_can('edit_post', $post_id)) {
return;
}
$my_data = isset($_POST['stammer_ai_chatbot_disable']) ? '1' : '';
update_post_meta($post_id, '_stammer_ai_chatbot_disable', $my_data);
}
add_action('save_post', 'stammer_ai_chatbot_save_meta_box_data');

// Enqueue the chat bubble script on the front end unless the checkbox is checked
function stammer_ai_chatbot_enqueue_script() {
$script = get_option('stammer_ai_chatbot_script', '');
$sitewide_enabled = get_option('stammer_ai_chatbot_sitewide', '1');

if (empty($script) || !$sitewide_enabled) {
return;
}

if (is_singular(['post', 'page'])) {
global $post;
$disable_chat_bubble = get_post_meta($post->ID, '_stammer_ai_chatbot_disable', true);
if (!$disable_chat_bubble) {
echo $script;
}
} else {
echo $script;
}
}
add_action('wp_footer', 'stammer_ai_chatbot_enqueue_script');

// Shortcode for embedding the chatbox iframe
function stammer_ai_chatbot_embed_shortcode($atts) {
$embed_code = get_option('stammer_ai_chatbot_embed_code', '');
return $embed_code;
}
add_shortcode('stammer_ai_chatbot_embed', 'stammer_ai_chatbot_embed_shortcode');

Step 1 — Creating the Chatbot Plugin

Make a Folder and call it stammer_ai_chatbot_plugin

Then create a file called stammer_ai_chatbot_plugin.php and paste the above plugin code in the file.

Zip the stammer_ai_chatbot_plugin folder if you haven’t already.

Step 2 — Installing and Activating the Plugin

  • Go to your WordPress admin dashboard.
  • Go to Plugins > Add New.
  • Click on Upload Plugin and upload the zipped file.
  • Install and activate the plugin.

Step 3 — Setting up the plugin in WordPress

Admin Settings

  • Go to Settings > Stammer AI Chatbot.
  • At the top, you will see a message indicating that the plugin requires an account at Stammer AI with a link to the affiliate URL.
  • Enter the chat bubble script tag in the provided text area.
  • Use the checkbox to enable or disable the chat bubble sitewide.
  • Enter the embed code for the iframe in the provided text area.
  • Save your settings.
WordPress Plugin AI Chatbot Settings
WordPress AI Chatbot Settings

Post/Page Settings

  • Edit any post or page where you want to disable the chat bubble.
  • On the right side, you will see a meta box titled “Chat Bubble Settings.”
  • Check the “Disable Chat Bubble” checkbox and update the post/page.

Shortcode for Embedding Chatbox

  • To embed the chatbox on any post or page, use the [stammer_ai_chatbot_embed] shortcode in the content editor.

For great results — Training AI Chatbots is extremely important.

If you need help with any AI Chatbot installation or training — contact me ✉️ here.

I also offer custom Chatbot consultancy and WordPress plugin development.

Note:

If you want our team to create a custom AI chatbot for your business, you can contact me ✉️

AI Growth Guys Contact ✉️

👉 Sign up to our free 5-Day email course to grow 🚀 and earn💲in the AI age

You can also sign up for my newsletter on how to use AI to earn more money.

Check out our YouTube Channel

Follow us at our website: AI Growth Guys

Note: This article contains affiliate links. If you purchase through a link, I may receive a small commission at no extra cost to you. I only recommend products I have experience with and personally use and love.

--

--

Addison Best
Addison Best

Written by Addison Best

AI Educator & Software Developer | Podcaster | Co-founder of 88Herbs | AI Course Instructor at Udemy | AI Growth Hacker @ www.aigrowthguys.com

No responses yet