Saturday, December 16, 2023
HomeMobile MarketingFastBots: Construct A Customized WordPress XML Sitemap For Coaching Your AI Bot

FastBots: Construct A Customized WordPress XML Sitemap For Coaching Your AI Bot


Martech Zone has 1000’s of articles, with lots of them outdated. I’ve labored on the positioning for a number of years to take away or replace tons of 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 need to do is prepare it on outdated articles.

FastBots is a ChatGPT-powered bot builder that you could 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 kind). I didn’t need to embrace 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 technique as I publish every article, however it is a nice place to begin for utilizing the platform.

The sitemap imports all of the hyperlinks to coach the AI Bot on:

FastBots: Train a bot from your site's sitemap.

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 embrace 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

Relatively 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 Identify: 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 Identify
*/

// 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 revealed
add_action('publish_post', 'mtz_update_sitemap_on_publish');

// Operate to replace the sitemap
operate mtz_update_sitemap_on_publish($post_id) {
    // Verify if the put up will not be an auto-draft
    if (get_post_status($post_id) != 'auto-draft') {
        mtz_build_dynamic_sitemap();
    }
}

// Essential operate to construct the sitemap
operate build_bot_sitemap() {
    international $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 kind 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');

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments