I'm trying to get my meta description to work in HAML and everything I try produces errors.
%meta{:name => "description", :content => "Some content"}/
%title
= data.page.title
The code above works. Now I try the following:
%meta{:name => "description", :content =>
= data.page.desc
}/
%title
= data.page.title
And I get unbalanced brackets error on the first line. What am I doing wrong?
The meta description is an HTML tag you can set for a post or page of your website. In it, you can describe what your page is about.
The <meta> tag defines metadata about an HTML document. Metadata is data (information) about data. <meta> tags always go inside the <head> element, and are typically used to specify character set, page description, keywords, author of the document, and viewport settings.
meta tags can be added anywhere in the HTML. The web crawlers can read them but the only issue is when you have to share your pages over some application like facebook messenger, whatsapp etc. These applications only read meta tags present inside the head tag.
Include a CTA in Your Meta DescriptionsUsing a call-to-action (CTA) in your meta descriptions is a great way to compel people to click on your website. You can use phrases like “Learn More” or “Click Here” or “Shop Now,” when they see it come up in SERPs.
In HAML, the hash that you use to specify the attributes for an element can contain valid Ruby code, so you don't need to use =
to evaluate a Ruby expression. Therefore, the code you're looking for is simply:
%meta{:name => "description", :content => data.page.desc}
Note that you don't need to append a /
to the end of the %meta
element declaration, as HAML will automatically treat it as a self-closing tag, like img
or br
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With