Using AI tools to create a WordPress snippet

This post about the use of AI tools to create a WordPress Snippet is part of a series where we share our learnings on managing a hobby website. This post is intended for WordPress hobby website administrators.

This is a very quick post to highlight how good the AI chatbots are getting at writing code. This is also a follow-on post to: A BajanThings 101 follow-up on AI Chatbots in 2025: ChatGPT, CoPilot, Gemini, DeepSeek, Grok & Claude. Why you MUST fact check the output…

BajanThings is built using the Ollie Pro theme.

We have added some additional functionality using the free version of the Code Snippets WordPress plugin. Here are the snippets we use:

  • Author Bio Formatting
  • Remove Website Technology Category from the Homepage listing of posts
  • Placing Google Analytics – (GA4) code after Footer

And we have some snippets that give us shortcode:

  • Shortcode: Estimated Time to Read
  • Shortcode: Count of Comments on Posts
  • Shortcode: Current Year…

We have just added a new snippet that auto generates the BajanThings list of contributing authors table on the Contributing Authors page:

  • Shortcode: Contributing Authors Table.

We used to generate the contributing authors table manually using a WordPress Table block like the one below that we manually edited:

Bill Hern – click here to see: Bill Hern’s posts.C. Don Lorde – click here to see: C. Don Lorde’s posts.
David Miles-Hanschell – click here to see: David Miles-Hanschells’ posts.David O’Carroll OBE – click here to see: David O’Carroll’s posts.
Greg Hoyos – click here to see: Greg Hoyos’ posts.Ian Clarke & Christopher Clarke – click here to see: Ian Clarke & Christopher Clarke’s posts.
Jan Weel – click here to see: Jan Weel’s posts.Jenny Gonsalves – click here to see: Jenny Gonsalves’ posts.
Jim Webster – click here to see: Jim Webster’s posts.John Fraser – click here to see: John Fraser’s posts.
John Fraser & Douglas Newsam – click here to see: John Fraser & Douglas Newsam’s posts.John Knox – click here to see: John Knox’s posts.
Kandace Chimbiri – click here to see: Kandace Chimbiri’s posts.Dr. Hon. Katharine Campbell – click here to see: Katharine Campbell’s posts.
Keith Mackie – click here to see: Keith Mackie’s posts.Dr. Kim Johnson – click here to see: Kim Johnson’s posts.
Lauren Kramer – click here to see: Lauren Kramer’s posts.Lyall Seale – click here to see: Lyall Seale’s posts.
Lynda Lewis & Jim Webster – click here to see: Lynda Lewis & Jim Webster’s posts.Mike Spence – click here to see: Mike Spence’s posts.
Nicholas Mayers – click here to see: Nicholas Mayers’ posts.Peter Burton – click here to see: Peter Burton’s posts.
Richard Rose – click here to see: Richard Roses posts.Roger Gibbs – click here to see: Roger Gibbs’ posts.
Shana Jones – click here to see: Shana Jones’ posts.Dr. Simon Kreindler – click here to see: Simon Kreindler’s posts.
Tyrone Roach – click here to see: Tyrone Roach’s posts.William Burton – click here to see: William Burton’s posts.
The BajanThings Team – click here to see: The BajanThings Team’s posts.
BajanThings Contributing Authors Table created manually using a Table block.

I got tired of updating this table manually and wondered if we could automate the process. I thought with the WordPress 6.8 update, maybe we could use a query loop…. not possible yet or not possible with my skill level yet!

Advertisements

I then started experiments with using: ChatGPT, CoPilot, Gemini, Grok, Claude and MyNinja. We found that ChatGPT gave us the best results.

This is what we asked ChatGPT to do (we used American English when spelling color!):

Please make a WordPress snippet to create a shortcode to provide an alphabetical list of all authors by display name linking to their author profile.
Do not show authors who have no posts.
The link to the author profile should use the target=”_blank” attribute and open in a new window.
WordPress is using the Ollie Pro theme, the Style is: Startup, the color Palette is: Default.
Call shortcode: BT_authors.
Call function: BT_authors_listing.
Make author username semi-bold font-weight:500.
Put author username = BajanThings-Team as the last entry.
After the author link add the author’s number of posts in brackets.
Display the list in a two column table. Use the formatting that the WordPress table block uses.
Make odd rows background color the Ollie color palette: Brand Accent.
Make even rows background color the Ollie color palette: Tint.
Include a cell border that uses the Ollie color palette: Border Base.
Use inline CSS for all the table formatting.

ChatGPT did a pretty good job. The only thing it did not do was to match the Ollie Pro theme colour palette. It did add some comments that allowed us to easily input the colour hex code. Our Ollie Pro default palette uses the following colours which we manually added in:

  • #DBDDFF – Brand Accent (odd rows)
  • #F8F7F9 – Tint (even rows)
  • #DADEE3 – Border Base (cell border)

This was the ChatGPT output which we setup as a snippet:

// WordPress Snippet produced by: ChatGPT
function BT_authors_listing() {
    // Fetch authors with published posts
    $authors = get_users([
        'who' => 'authors',
        'orderby' => 'display_name',
        'order'   => 'ASC',
        'has_published_posts' => true,
    ]);

    $bajanthings_team = null;
    $filtered_authors = [];

    // Filter out authors with no posts and separate BajanThings-Team
    foreach ($authors as $author) {
        $post_count = count_user_posts($author->ID);
        if ($post_count === 0) continue;

        if ($author->user_login === 'BajanThings-Team') {
            $bajanthings_team = $author;
        } else {
            $filtered_authors[] = $author;
        }
    }

    // Add BajanThings-Team at the end if they have posts
    if ($bajanthings_team && count_user_posts($bajanthings_team->ID) > 0) {
        $filtered_authors[] = $bajanthings_team;
    }

    // Ollie Pro Theme Color Palette (adjust these HEX values if needed)
    $brand_accent = '#DBDDFF'; // Brand Accent
    $tint         = '#F8F7F9'; // Tint
    $border_base  = '#DADEE3'; // Border Base

    // Start generating the table output
    ob_start();
    echo '<table style="width:100%; border-collapse:collapse; font-family:inherit; font-size:1rem;">';

    $row_count = 0;
    for ($i = 0; $i < count($filtered_authors); $i += 2) {
        $row_color = ($row_count % 2 === 0) ? $brand_accent : $tint;
        echo '<tr style="background-color:' . esc_attr($row_color) . '; border:1px solid ' . esc_attr($border_base) . ';">';

        // First column
        $author1 = $filtered_authors[$i];
        $posts1 = count_user_posts($author1->ID);
        echo '<td style="padding:0.75em 1em; border:1px solid ' . esc_attr($border_base) . ';">';
        echo '<a href="' . esc_url(get_author_posts_url($author1->ID)) . '" target="_blank" style="text-decoration:none; font-weight:500;">';
        echo esc_html($author1->display_name) . '</a> (' . intval($posts1) . ')';
        echo '</td>';

        // Second column
        if (isset($filtered_authors[$i + 1])) {
            $author2 = $filtered_authors[$i + 1];
            $posts2 = count_user_posts($author2->ID);
            echo '<td style="padding:0.75em 1em; border:1px solid ' . esc_attr($border_base) . ';">';
            echo '<a href="' . esc_url(get_author_posts_url($author2->ID)) . '" target="_blank" style="text-decoration:none; font-weight:500;">';
            echo esc_html($author2->display_name) . '</a> (' . intval($posts2) . ')';
            echo '</td>';
        } else {
            // Empty second column if odd number of authors
            echo '<td style="padding:0.75em 1em; border:1px solid ' . esc_attr($border_base) . ';"></td>';
        }

        echo '</tr>';
        $row_count++;
    }

    echo '</table>';
    return ob_get_clean();
}
add_shortcode('BT_authors', 'BT_authors_listing');

Here is the output for the shortcode for the original snippet: BT_authors (which is surrounded by square brackets as it’s a shortcode).

Bill Hern (5)C. Don Lorde (1)
Clement Griffiths (1)David Miles-Hanschell (1)
David O'Carroll OBE (7)Greg Hoyos (2)
Ian Clarke & Christopher Clarke (2)Jan Weel (1)
Jenny Gonsalves (1)Jim Webster (13)
John Fraser (2)John Fraser & Douglas Newsam (2)
John Knox (6)Kandace Chimbiri (1)
Katharine Campbell (1)Keith Mackie (1)
Kim Johnson (3)Lauren Kramer (1)
Lyall Seale (1)Lynda Lewis & Jim Webster (1)
Mike Spence (1)Nicholas Mayers (1)
Peter Burton (62)Richard Rose (1)
Roger Gibbs (2)Shana Jones (1)
Simon Kreindler (1)Tyrone Roach (2)
William Burton (104)BajanThings Team (14)

We are pretty pleased with the output from ChatGPT. The only thing we needed to edit manually in the code snippet were the three background colours detailed above. Now whenever a new contributing author is added the table auto updates. How cool is that! And it saves us a truck load of time!

We have since tweaked the original snippet to make two snippets, grouping the authors into two groups:

  • Group 1 producing a table of the post by the BajanThings team – BT_founding_authors
  • Group 2 producing a table of the post by our guest authors – BT_contributing_authors.

For the BT_founding_authors snippet we asked Chapt GPT to do the following:

This table was produced by a snippet generated by ChatGPT BT_authors (square brackets removed from BT_authors as it’s a shortcode).
Please amend the snippet so that:
shortcode is: BT_founding_authors.
function is: BT_founding_authors_listing.
Please only show the following users in the listing: username = Decimus_Burton, username = Burts, username = BajanThings-Team
Please explicitly ordered as: Burts, Decimus_Burton, BajanThings-Team

And this was the ChatGPT output:

// WordPress Snippet amended by ChatGPT
function BT_founding_authors_listing() {
    // Define the allowed founding authors in the required order
    $allowed_authors = ['Burts', 'Decimus_Burton', 'BajanThings-Team'];

    // Fetch only the specified authors
    $authors = get_users([
        'login__in' => $allowed_authors,
        'has_published_posts' => true,
    ]);

    // Reorder authors according to $allowed_authors array
    $ordered_authors = [];
    foreach ($allowed_authors as $login) {
        foreach ($authors as $author) {
            if ($author->user_login === $login) {
                $ordered_authors[] = $author;
            }
        }
    }

    // Ollie Pro Theme Color Palette (adjust these HEX values if needed)
    $brand_accent = '#DBDDFF'; // Brand Accent
    $tint         = '#F8F7F9'; // Tint
    $border_base  = '#DADEE3'; // Border Base

    // Start generating the table output
    ob_start();
    echo '<table style="width:100%; border-collapse:collapse; font-family:inherit; font-size:1rem;">';

    $row_count = 0;
    for ($i = 0; $i < count($ordered_authors); $i += 2) {
        $row_color = ($row_count % 2 === 0) ? $brand_accent : $tint;
        echo '<tr style="background-color:' . esc_attr($row_color) . '; border:1px solid ' . esc_attr($border_base) . ';">';

        // First column
        $author1 = $ordered_authors[$i];
        $posts1 = count_user_posts($author1->ID);
        echo '<td style="padding:0.75em 1em; border:1px solid ' . esc_attr($border_base) . ';">';
        echo '<a href="' . esc_url(get_author_posts_url($author1->ID)) . '" target="_blank" style="text-decoration:none; font-weight:500;">';
        echo esc_html($author1->display_name) . '</a> (' . intval($posts1) . ')';
        echo '</td>';

        // Second column
        if (isset($ordered_authors[$i + 1])) {
            $author2 = $ordered_authors[$i + 1];
            $posts2 = count_user_posts($author2->ID);
            echo '<td style="padding:0.75em 1em; border:1px solid ' . esc_attr($border_base) . ';">';
            echo '<a href="' . esc_url(get_author_posts_url($author2->ID)) . '" target="_blank" style="text-decoration:none; font-weight:500;">';
            echo esc_html($author2->display_name) . '</a> (' . intval($posts2) . ')';
            echo '</td>';
        } else {
            // Empty second column if odd number of authors
            echo '<td style="padding:0.75em 1em; border:1px solid ' . esc_attr($border_base) . ';"></td>';
        }

        echo '</tr>';
        $row_count++;
    }

    echo '</table>';
    return ob_get_clean();
}
add_shortcode('BT_founding_authors', 'BT_founding_authors_listing');

Here is the output for the shortcode for the revised snippet: BT_founding_authors (which is surrounded by square brackets as it’s a shortcode).

William Burton (104)Peter Burton (62)
BajanThings Team (14)

For the BT_contributing_author snippet we asked Chapt GPT to do the following:

This table was produced by a snippet generated by ChatGPT BT_authors (square brackets removed from BT_authors as it’s a shortcode).
Please amend the snippet so that:
shortcode is: BT_contributing_authors.
function is: BT_contributing_authors_listing.
Please exclude the following users in the listing: username = Decimus_Burton, username = Burts, username = BajanThings-Team

And this was the ChatGPT output:

// WordPress Snippet amended by ChatGPT
function BT_contributing_authors_listing() {
    // Users to exclude
    $excluded_authors = ['Decimus_Burton', 'Burts', 'BajanThings-Team'];

    // Fetch authors with published posts, ordered alphabetically by display name
    $authors = get_users([
        'who' => 'authors',
        'orderby' => 'display_name',
        'order'   => 'ASC',
        'has_published_posts' => true,
    ]);

    $filtered_authors = [];

    // Filter out excluded users and authors with no posts
    foreach ($authors as $author) {
        if (in_array($author->user_login, $excluded_authors, true)) {
            continue;
        }
        $post_count = count_user_posts($author->ID);
        if ($post_count === 0) continue;

        $filtered_authors[] = $author;
    }

    // Ollie Pro Theme Color Palette (adjust these HEX values if needed)
    $brand_accent = '#DBDDFF'; // Brand Accent
    $tint         = '#F8F7F9'; // Tint
    $border_base  = '#DADEE3'; // Border Base

    // Start generating the table output
    ob_start();
    echo '<table style="width:100%; border-collapse:collapse; font-family:inherit; font-size:1rem;">';

    $row_count = 0;
    for ($i = 0; $i < count($filtered_authors); $i += 2) {
        $row_color = ($row_count % 2 === 0) ? $brand_accent : $tint;
        echo '<tr style="background-color:' . esc_attr($row_color) . '; border:1px solid ' . esc_attr($border_base) . ';">';

        // First column
        $author1 = $filtered_authors[$i];
        $posts1 = count_user_posts($author1->ID);
        echo '<td style="padding:0.75em 1em; border:1px solid ' . esc_attr($border_base) . ';">';
        echo '<a href="' . esc_url(get_author_posts_url($author1->ID)) . '" target="_blank" style="text-decoration:none; font-weight:500;">';
        echo esc_html($author1->display_name) . '</a> (' . intval($posts1) . ')';
        echo '</td>';

        // Second column
        if (isset($filtered_authors[$i + 1])) {
            $author2 = $filtered_authors[$i + 1];
            $posts2 = count_user_posts($author2->ID);
            echo '<td style="padding:0.75em 1em; border:1px solid ' . esc_attr($border_base) . ';">';
            echo '<a href="' . esc_url(get_author_posts_url($author2->ID)) . '" target="_blank" style="text-decoration:none; font-weight:500;">';
            echo esc_html($author2->display_name) . '</a> (' . intval($posts2) . ')';
            echo '</td>';
        } else {
            // Empty second column if odd number of authors
            echo '<td style="padding:0.75em 1em; border:1px solid ' . esc_attr($border_base) . ';"></td>';
        }

        echo '</tr>';
        $row_count++;
    }

    echo '</table>';
    return ob_get_clean();
}
add_shortcode('BT_contributing_authors', 'BT_contributing_authors_listing');

Here is the output for the shortcode for the revised snippet: BT_contributing_authors (which is surrounded by square brackets as it’s a shortcode).

Bill Hern (5)C. Don Lorde (1)
Clement Griffiths (1)David Miles-Hanschell (1)
David O'Carroll OBE (7)Greg Hoyos (2)
Ian Clarke & Christopher Clarke (2)Jan Weel (1)
Jenny Gonsalves (1)Jim Webster (13)
John Fraser (2)John Fraser & Douglas Newsam (2)
John Knox (6)Kandace Chimbiri (1)
Katharine Campbell (1)Keith Mackie (1)
Kim Johnson (3)Lauren Kramer (1)
Lyall Seale (1)Lynda Lewis & Jim Webster (1)
Mike Spence (1)Nicholas Mayers (1)
Richard Rose (1)Roger Gibbs (2)
Shana Jones (1)Simon Kreindler (1)
Tyrone Roach (2)

The trick here was we had already done the hard work getting the BT_authors snippet – the only manual intervention was ChatGPT was not able to match the Ollie Pro theme colour palette, however, it did add some comments that allowed us to easily input the actual colour hex code. Giving ChatGPT the amended BT_authors snippet as the base for the snippet code tweak meant, the theme palette colours were already in place and we did not have to change them!

Changes like this work best where ChatGPT has something that already works that it can amend – otherwise you have to go thought the training and refining process all over again.


I was inspired to write this up having listened to Mike McAlister’s video blog: AI is coming to WordPress.

How great will it be, if within WordPress I could have done this and it automatically linked the formatting to the theme. It was only ChatGPT that gave us formatting options that worked!

Advertisements

Click here to see Mike’s recently update personal webpage built using Ollie Pro of course.


If you enjoyed this post leave a comment…

0 responses to “Using AI tools to create a WordPress snippet”

Leave a Reply

Your email address will not be published. Required fields are marked *


This site uses Akismet to reduce spam. Learn how your comment data is processed.

You might also find these posts of interest…

Advertisements

Search BajanThings:

Help Us Share More Bajan Stories – Make a Donation:

BajanThings is a passion project dedicated to preserving and sharing Bajan culture, stories, and history.

Your support helps cover the annual costs of running the BajanThings website and fuels our mission to document and share Bajan stories for future generations.

We accept donations via Stripe and PayPal.

Thank you for your support!

Subscribe to BajanThings:

If you would like to be kept informed when there are updates to BajanThings please subscribe to our e-mail update notification. Whenever there is new content added to BajanThings, you will receive an e-mail telling you of the update:

Advertisements

Notice Board:

Thor Heyerdahl’s Ra Expeditions to Barbados: Ra I 1969, Ra II 1970 has been updated with some additional Black & White photos.

Barbados Oceanographic Research Facility 1957 – 1979 has been updated with some photos of the remnant underseas SOSUS cable.

The BajanThings 101 on AI chatbots has been updated for 2025 to include: ChatGPT, CoPilot, Gemini, DeepSeek, Grok (xAI) & Claude.

Lord Nelson’s statue – Bridgetown, Barbados has been updated following its removal on 16th November 2020 with details of the public subscribers and details about the forged Nelson-Taylor letter.

The Printed Maps of Barbados 1500 – 1980s has been updated and split into 5 sections: 1500s – 1700, 1700 – 1800, 1800 – 1900, 1900 – 1980s & Addendums.

P/O George HF Inniss: 31st May 1916 to 5th February 1941 has been updated.

St. Philip, Barbados in the 1950s & 1960s. A very brief recollection of the people and events updated to include details of the homemade helicopter built by Three Houses factory manager Bob Reece.

Do You Want The Truth Or Something Beautiful? The Empire Windrush story has been updated.

Errol Barrow – Statesman, Prime Minister of Barbados, RAF Navigator World War II has been updated.

Torpedoing of the Cornwallis in Carlisle Bay, Barbados, 11th September 1942 has been updated.

Memorials for departed friends has been updated, a fourth cairn has been added.

High Altitude Research Project (HARP) 1962 – 1967 has been updated.

British Ship: Scottish Star Torpedoed – 19th February 1942 has been updated with a section on Michael Doyle AB.

Barbados Island life: photographs and stories by Craig Burleigh that celebrate Barbados island life in the 1970s

Contact BajanThings:

Click on the: Contact us button below to go to the BajanThings contact page:

Advertisements