Skip to content

Instantly share code, notes, and snippets.

@alfredo-wpmudev
Created June 19, 2024 00:39
Show Gist options
  • Save alfredo-wpmudev/b46e234e903688737797d7f3f7be1a57 to your computer and use it in GitHub Desktop.
Save alfredo-wpmudev/b46e234e903688737797d7f3f7be1a57 to your computer and use it in GitHub Desktop.
AI Chat Assistant using Shortcode. [iframe-chat link='https://URL_FOR_IFRAME']
<?php
/**
* Plugin Name: Shortcode for Iframe Chat
* Description: Display iframe using a shortcode to insert in a page or post or any place that accept shortcodes.
* Version: 0.1
* Author: Alfredo Galano Loyola
* Author URI: https://wpmudev.com
*/
function listing_iframe_chat($atts) {
$default = array(
'link' => '#',
);
$a = shortcode_atts($default, $atts);
$iframe_html = '<iframe src="'.$a['link'].'" width="100%" height="500" title="Chat" frameborder="0"></iframe>';
$html ='<div id="ia-helper-button"><button class="ia-helper">IA Assistant</button></div>';
$html .='<div id="ia-helper-chat-container">';
$html .= $iframe_html ;
$html .='</div>';
$html .='<style>';
$html .='.ia-helper{background-color:#31B0D5;color:white;padding:10px 20px;border-radius:4px;border-color: #46b8da;text-transform:uppercase;}';
$html .='#ia-helper-button{position:fixed;bottom:10px;right:10px;z-index:9999;cursor:pointer;}';
$html .='#ia-helper-chat-container{position:fixed;width:350px;height:500px;bottom:55px;right:10px;z-index:9999;}';
$html .='</style>';
$html .='<script>';
$html .='jQuery( document ).ready(function() {';
$html .='jQuery(".ia-helper").on( "click",function(){jQuery( "#ia-helper-chat-container" ).toggle();});';
$html .='});';
$html .='</script>';
return $html;
}
add_shortcode('iframe-chat', 'listing_iframe_chat');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment