开发者

Problem setting unique meta keywords for each page

开发者 https://www.devze.com 2023-03-09 18:40 出处:网络
I am currently in the process of trying to add unique page titles and keywords to the pages on a website.Previously I had set the title, keywords and description in the application layout but ideally

I am currently in the process of trying to add unique page titles and keywords to the pages on a website. Previously I had set the title, keywords and description in the application layout but ideally i would like to be able to set these individually for each page.

Looking at previous questions, I found it was possible to set the title using the code below:

[In application layout]

<title><%=h yield(:title) %></title>

[In page view]

<% content_for :title, "Content here..." %>

This worked just as hoped. However, I then tried to apply the same logic to the meta keywords:

<meta name="keywor开发者_开发知识库ds" content=<%=h yield(:keywords) %> >

<% content_for :keywords, "word1, word2, word3" %>

This doesn't give an error, however, when I view the page source there are " missing, i.e. it appears as:

<meta name="keywords" content=word1, word2, word3 >

rather than

<meta name="keywords" content="word1, word2, word3">

Is there an easy way to remedy this, or am I barking up the wrong tree trying to do it this way?


Just add quotes to your code:

<meta name="keywords" content="<%=h yield(:keywords) %>">
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号