generative AI

How to use AI to automatically add relevant meta descriptions to all your CMS pages

Learn how to use AI to automatically add relevant meta descriptions to all your CMS pages. Increase your website's visibility and attract more users with enticing meta descriptions.


Meta description is the short text that appears below each link when we search on Google, for example. Its main purpose is to entice users to click on the link. In other words, to convince them that the content presented is relevant and that the site is worth a visit. 

As many potential customers can find your business through search engines, it is essential to maintain a good meta description for each page of your site. This task, however, is not always possible: as the site scales, it becomes difficult to keep track of these small details on each page. In addition, creating meta descriptions manually for each of the 300 pages on a site, for example, is often impractical. 

Today, however, we have an extremely useful tool: AI! Imagine if you could simply create a script that automatically adds well-crafted meta descriptions to all your pages. That's what we're going to do together today! Let's go:

In this tutorial, we will use Python to create the scripts, AI21 Labs and the CMS used will be Hubspot. But you can apply the idea using other programming languages, as well as other AI tools and CMS.

NOTE_1: You can copy-paste the code from this GitHub repository.
NOTE_2: If you prefer, I've created a step-by-step tutorial on YouTube:

  1. Create an account at AI21 Labs and generate an API key. The process is very simple and when you create an account, you get 90 dollars to make the requests which will probably be more than enough for you to change all the meta descriptions on your site.

    Captura de Tela 2023-12-29 às 14.28.59

  2. Generate an API Key to access your Hubspot API. To do this, you'll first need to create a private app. I won't go into the details of this part here, but you can see the step-by-step in Hubspot's own documentation. 

  3. In the code, import the following libraries, create constants for the base URLs and use your API keys to create the headers for the two APIs (Hubspot and AI21 Labs):

    Captura de Tela 2023-12-29 às 14.16.43
  4. GET all the pages in your CMS that you want to add the meta description to:
     
    Captura de Tela 2023-12-29 às 14.17.04
     
  5. Create a prompt to send as a request in AI21 Labs. In this case, for example, we'll use the url of each page as information for creating the prompts:

    Captura de Tela 2023-12-29 às 14.19.28

  6. Now we'll run a for loop in the pages list. In this loop, we'll create the meta descriptions for each page and then perform a PATCH, adding the meta descriptions to each of the pages on your site:

    Captura de Tela 2023-12-29 às 14.21.45

Done, meta descriptions duly added! See you next time! ✨

Similar posts

Get notified on new marketing insights

Be the first to know about new B2B SaaS Marketing insights to build or refine your marketing function with the tools and knowledge of today’s industry.