CMS Development

gsantos1
Contributor

Page meta title and description based on combination of hubDB columns

SOLVE

Hello community!

 

I've been developing my new blog and list site with hubDB, loving it!

But I'm having dificulty working this meta optimization and maybe someone solved something like this before:

 

Each row in my hubDB table has columns like keywords, countries, availability, and I'm combining these columns on the H1 and first paragraph of the dynamic pages. Someting like:

 

H1 = column3 + row_title + column5 + column 6

Description = row_title + column7 + column_description

 

On some pages, I use the total number of rows of a specific query on the H1 too:

H1 = column3 + totalrowsquery + row_title

 

The issue is: I need this combination of columns to also be applied to the meta title and meta description of the dynamic pages. I can select a specific column on the hubDB table for description, but I can't apply the same combination of columns (maybe this could be a future update on HubDB? 😅 ).

 

Has anyone ever worked something like this before?

 

Thank you in advance!

Cheers

1 Accepted solution
assi
Solution
Guide

Page meta title and description based on combination of hubDB columns

SOLVE

Hi @gsantos1 

 

Maybe you can do what you want. Basic thought is write title and meta description codes by yourself. The problem is the codes generated from  {{ standard_header_includes }} such as og:title and og:description.

But acutually we can control them by using regex_replace filter. 

 

Codes like below: 

 

{%- if dynamic_page_hubdb_row -%}
  {% set title = dynamic_page_hubdb_row.hs_name ~ dynamic_page_hubdb_row.your_column %}
  {% set description = dynamic_page_hubdb_row.your_column ~ dynamic_page_hubdb_row.your_column2 %}
  <title>{{ title }}</title>
  <meta name="description" content="{{ description }}">      
  {{ standard_header_includes
      |regex_replace('"og:title" content=".*"', '"og:title" content="{{ title }}"')
      |regex_replace('"twitter:title" content=".*"', '"twitter:title" content="{{ title }}"')
      |regex_replace('"og:description" content=".*"', '"og:description" content="{{ description }}"')
      |regex_replace('"twitter:description" content=".*"', '"twitter:description" content="{{ description }}"')
  }}
{%- else -%}
  <title>{{ page_meta.html_title }}</title>
  <meta name="description" content="{{ page_meta.meta_description }}">
  {{ standard_header_includes }}
{%- endif -%}

 

Good Luck, 


HS Tech Ninja Atsushi Handa
独立しました:https://assialiholic.net/about
Twitter logo

View solution in original post

4 Replies 4
assi
Solution
Guide

Page meta title and description based on combination of hubDB columns

SOLVE

Hi @gsantos1 

 

Maybe you can do what you want. Basic thought is write title and meta description codes by yourself. The problem is the codes generated from  {{ standard_header_includes }} such as og:title and og:description.

But acutually we can control them by using regex_replace filter. 

 

Codes like below: 

 

{%- if dynamic_page_hubdb_row -%}
  {% set title = dynamic_page_hubdb_row.hs_name ~ dynamic_page_hubdb_row.your_column %}
  {% set description = dynamic_page_hubdb_row.your_column ~ dynamic_page_hubdb_row.your_column2 %}
  <title>{{ title }}</title>
  <meta name="description" content="{{ description }}">      
  {{ standard_header_includes
      |regex_replace('"og:title" content=".*"', '"og:title" content="{{ title }}"')
      |regex_replace('"twitter:title" content=".*"', '"twitter:title" content="{{ title }}"')
      |regex_replace('"og:description" content=".*"', '"og:description" content="{{ description }}"')
      |regex_replace('"twitter:description" content=".*"', '"twitter:description" content="{{ description }}"')
  }}
{%- else -%}
  <title>{{ page_meta.html_title }}</title>
  <meta name="description" content="{{ page_meta.meta_description }}">
  {{ standard_header_includes }}
{%- endif -%}

 

Good Luck, 


HS Tech Ninja Atsushi Handa
独立しました:https://assialiholic.net/about
Twitter logo
gsantos1
Contributor

Page meta title and description based on combination of hubDB columns

SOLVE

Hi @assi 

I'm definatelly having a go with your solution, thank you!

 

Do you reckon is possible to achieve something similar outside of the header?

Like a module after <body> that could override meta title, meta description and standard_header_includes?

 

Thanks a lot for your help!

Cheers

assi
Guide

Page meta title and description based on combination of hubDB columns

SOLVE

Hi @gsantos1 

 

What you're meaning is "Whether modules in <body> can rewrite elements in <head> such as meta title, description, standard_header_includes, etc." right? Unfotunatelly, it is impossible.  Rewriting them must always be done in the template.

 

If you still have some problems, I could answer if you share them with me!

 

Atsushi


HS Tech Ninja Atsushi Handa
独立しました:https://assialiholic.net/about
Twitter logo
gsantos1
Contributor

Page meta title and description based on combination of hubDB columns

SOLVE

Yes, that's what I was planning to do.

That's Ok, I will work with your suggestion.

 

Thanks for your help @assi .

Cheers