kpumuk / meta-tags

Search Engine Optimization (SEO) for Ruby on Rails applications.
MIT License
2.73k stars 275 forks source link

Override default description? #139

Closed cmalpeli closed 7 years ago

cmalpeli commented 7 years ago

Is there a way to provide a default meta description and then override it on a view by view basis? Similar to how is handled?</p> </div> </div> <div class="comment"> <div class="user"> <a rel="noreferrer nofollow" target="_blank" href="https://github.com/kpumuk"><img src="https://avatars.githubusercontent.com/u/10163?v=4" />kpumuk</a> commented <strong> 7 years ago</strong> </div> <div class="markdown-body"> <p>You can use <code><% set_meta_tags description: 'Other description' %></code> or <code><% description 'Other description' %></code> in your views</p> </div> </div> <div class="comment"> <div class="user"> <a rel="noreferrer nofollow" target="_blank" href="https://github.com/cmalpeli"><img src="https://avatars.githubusercontent.com/u/900950?v=4" />cmalpeli</a> commented <strong> 7 years ago</strong> </div> <div class="markdown-body"> <p>Thanks for the quick reply! That is what I'm doing.</p> <p>Main Layout:</p> <pre><code> <% set_meta_tags site: home_meta_title, description: "Default description", charset: "utf-8", canonical: canonical_url, icon: favicon, viewport: "width=device-width, initial-scale=1, maximum-scale=1", twitter:{widgets:{csp: "on"}} %> <%= display_meta_tags reverse: true %></code></pre> <p>My View:</p> <pre><code><% set_meta_tags title: @job.seo_title, description: @job.short_description, og: { title: @job.title, type: 'article', url: @job.url, image: @job.logo.opengraph, site_name: @current_tenant.name } %></code></pre> <p>But my output is: <code><meta name="description" content="Default description" /></code></p> </div> </div> <div class="comment"> <div class="user"> <a rel="noreferrer nofollow" target="_blank" href="https://github.com/kpumuk"><img src="https://avatars.githubusercontent.com/u/10163?v=4" />kpumuk</a> commented <strong> 7 years ago</strong> </div> <div class="markdown-body"> <p>Checking, thank you for the report</p> </div> </div> <div class="comment"> <div class="user"> <a rel="noreferrer nofollow" target="_blank" href="https://github.com/kpumuk"><img src="https://avatars.githubusercontent.com/u/10163?v=4" />kpumuk</a> commented <strong> 7 years ago</strong> </div> <div class="markdown-body"> <p>Could you remove <code>set_meta_tags</code> and pass arguments directly to <code>display_meta_tags</code>? Like:</p> <pre><code class="language-erb"><%= display_meta_tags( site: home_meta_title, description: "Default description", charset: "utf-8", canonical: canonical_url, icon: favicon, reverse: true, viewport: "width=device-width, initial-scale=1, maximum-scale=1", twitter: { widgets: { csp: "on" } }, ) %></code></pre> <p>If you use <code>set_meta_tags</code> in the layout – it will override the values you set in your views. If you pass values to <code>display_meta_tags</code> – they will be used as defaults, and views will override the values.</p> </div> </div> <div class="comment"> <div class="user"> <a rel="noreferrer nofollow" target="_blank" href="https://github.com/cmalpeli"><img src="https://avatars.githubusercontent.com/u/900950?v=4" />cmalpeli</a> commented <strong> 7 years ago</strong> </div> <div class="markdown-body"> <p>That worked great - thanks!!</p> </div> </div> <div class="comment"> <div class="user"> <a rel="noreferrer nofollow" target="_blank" href="https://github.com/kpumuk"><img src="https://avatars.githubusercontent.com/u/10163?v=4" />kpumuk</a> commented <strong> 7 years ago</strong> </div> <div class="markdown-body"> <p>You're welcome</p> </div> </div> <div class="comment"> <div class="user"> <a rel="noreferrer nofollow" target="_blank" href="https://github.com/aapljack"><img src="https://avatars.githubusercontent.com/u/630399?v=4" />aapljack</a> commented <strong> 6 years ago</strong> </div> <div class="markdown-body"> <p>@kpumuk I am having a similar issue. I am trying to put in a default description, but when I use<code><%= display_meta_tags( description: 'Default description' ) %></code> I get nothing back in the layout. I am using version 2.4.1 of the gem since I am on an earlier version of Ruby. Any advice?</p> </div> </div> <div class="comment"> <div class="user"> <a rel="noreferrer nofollow" target="_blank" href="https://github.com/kpumuk"><img src="https://avatars.githubusercontent.com/u/10163?v=4" />kpumuk</a> commented <strong> 6 years ago</strong> </div> <div class="markdown-body"> <p>@aapljack Could you provide more details?</p> <ol> <li>where do you have <code>display_meta_tags</code> declared? (layout? view?) If it is a layout, please make sure it is the one used for your controller.</li> <li>do you change description via <code>set_meta_tags</code> or <code>description</code> helpers?</li> <li>do you by any chance have <code>@page_description</code> instance variable declared in your controller?</li> </ol> </div> </div> <div class="comment"> <div class="user"> <a rel="noreferrer nofollow" target="_blank" href="https://github.com/aapljack"><img src="https://avatars.githubusercontent.com/u/630399?v=4" />aapljack</a> commented <strong> 6 years ago</strong> </div> <div class="markdown-body"> <p>@kpumuk Thanks for the response. Some details..</p> <ol> <li>I have <code>display_meta_tags</code> declared in the layout and it is the one being used by the controller.</li> <li>I am attempting to set the description via <code>set_meta_tags</code> in the controller. To test, I have completely removed this from the controller and I still do not get the default description set in the <code>display_meta_tags</code>.</li> <li>I have an instance variable of <code>@page</code> set and am pulling in the description with <code>@page.description</code>. When no description is present, I want it to fall back to the default.</li> </ol> </div> </div> <div class="page-bar-simple"> </div> <div class="footer"> <ul class="body"> <li>© <script> document.write(new Date().getFullYear()) </script> Githubissues.</li> <li>Githubissues is a development platform for aggregating issues.</li> </ul> </div> <script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.min.js"></script> <script src="/githubissues/assets/js.js"></script> <script src="/githubissues/assets/markdown.js"></script> <script src="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.4.0/build/highlight.min.js"></script> <script src="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.4.0/build/languages/go.min.js"></script> <script> hljs.highlightAll(); </script> </body> </html>