Martech Zone has hundreds of articles, with a lot of them outdated. I’ve labored on the positioning for a number of years to take away or replace a whole lot of articles, however I nonetheless have many extra. On the identical time, I’d like to coach a pure language bot with my content material, however the very last thing I wish to do is prepare it on outdated articles.
FastBots is a ChatGPT-powered bot builder you can initially prepare utilizing your sitemap (or different choices). I wanted a filtered sitemap that included all articles modified since a selected date. Moreover, I needed to incorporate my pages and acronyms (a customized put up sort). I didn’t wish to embody archive pages for classes and tags or have my dwelling web page because it’s additionally an archive.
Utilizing the code I’m offering on the finish of this text; I constructed a customized WordPress plugin that creates a customized XML sitemap that dynamically refreshes every time I publish a put up. FastBots doesn’t have an automatic retraining methodology as I publish every article, however it is a nice start line for utilizing the platform.
The sitemap imports all of the hyperlinks to coach the AI Bot on:
All pages at the moment are imported, and you may prepare your bot on the relevant information. You even have the chance to take away particular pages. FastBots additionally allowed me to customise my AI bot’s branding and even embody a hyperlink to a related article in my response. There’s additionally a lead request constructed into the platform.
The platform labored flawlessly… you can provide my bot a check drive right here:
Launch Martech Zone’s Bot, Marty Construct Your FastBots AI Bot
Customized XML Sitemap
Moderately than add this performance to my theme, I constructed a customized WordPress plugin to construct out a Sitemap. Simply add a listing in your plugins folder, then a PHP file with the next code:
<?php
/*
Plugin Title: Bot Sitemap
Description: Dynamically generates an XML sitemap together with posts modified since a selected date and updates it when a brand new article is added.
Model: 1.0
Creator: Your Title
*/
// Outline the date since when to incorporate modified posts (format: Y-m-d)
$mtz_modified_since_date="2020-01-01";
// Register the operate to replace the sitemap when a put up is printed
add_action('publish_post', 'mtz_update_sitemap_on_publish');
// Operate to replace the sitemap
operate mtz_update_sitemap_on_publish($post_id) {
// Test if the put up isn't an auto-draft
if (get_post_status($post_id) != 'auto-draft') {
mtz_build_dynamic_sitemap();
}
}
// Major operate to construct the sitemap
operate build_bot_sitemap() {
world $mtz_modified_since_date;
$args = array(
'post_type' => 'put up',
'date_query' => array(
'column' => 'post_modified',
'after' => $mtz_modified_since_date
),
'posts_per_page' => -1 // Retrieve all matching posts
);
$postsForSitemap = get_posts($args);
// Fetch all 'acronym' customized put up sort posts
$acronymPosts = get_posts(array(
'post_type' => 'acronym',
'posts_per_page' => -1,
));
// Fetch all pages besides the house web page
$pagesForSitemap = get_pages();
$home_page_id = get_option('page_on_front');
$sitemap = '<?xml model="1.0" encoding="UTF-8"?>';
$sitemap .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
foreach($postsForSitemap as $put up) {
setup_postdata($put up);
if ($post->ID != $home_page_id) {
$sitemap .= '<url>'.
'<loc>'. get_permalink($put up) .'</loc>'.
'<lastmod>'. get_the_modified_date('c', $put up) .'</lastmod>'.
'<changefreq>weekly</changefreq>'.
'</url>';
}
}
foreach($acronymPosts as $put up) {
setup_postdata($put up);
if ($post->ID != $home_page_id) {
$sitemap .= '<url>'.
'<loc>'. get_permalink($put up) .'</loc>'.
'<lastmod>'. get_the_modified_date('c', $put up) .'</lastmod>'.
'<changefreq>weekly</changefreq>'.
'</url>';
}
}
foreach($pagesForSitemap as $web page) {
setup_postdata($web page);
if ($page->ID != $home_page_id) {
$sitemap .= '<url>'.
'<loc>'. get_permalink($web page) .'</loc>'.
'<lastmod>'. get_the_modified_date('c', $web page) .'</lastmod>'.
'<changefreq>month-to-month</changefreq>'.
'</url>';
}
}
wp_reset_postdata();
$sitemap .= '</urlset>';
file_put_contents(get_home_path().'bot-sitemap.xml', $sitemap);
}
// Activate the preliminary sitemap construct on plugin activation
register_activation_hook(__FILE__, 'build_bot_sitemap');