简体   繁体   English

在Shopify中为博客标签设置元标题和描述

[英]Set Meta Title and Description for Blog Tags in Shopify

I'm starting to migrate my blog from wordpress to shopify. 我开始将我的博客从wordpress迁移到shopify。 I'm trying to use the blog tags to split posts into categories. 我正在尝试使用博客标签将帖子分为几类。

The problem is the meta titles for tags are auto generated, and the meta description is auto copied from the blog pages meta description. 问题是标签的元标题是自动生成的,并且元描述是从博客页面元描述中自动复制的。 This is going to be awful SEO for the high level category/tag pages. 对于高级类别/标签页面,这将是非常糟糕的SEO。

I spoke to support who say there is no way of editing this info. 我说过支持谁说无法编辑此信息。 Could anyone suggest a way of editing the theme files to add unique titles and descriptions for each tag? 有人可以建议一种编辑主题文件以为每个标签添加唯一标题和描述的方法吗? There will only be about 10 but using conditionals on every page load seems pretty terrible? 大约只有10个,但是在每个页面加载中使用条件语句似乎很可怕吗? I'm not a coder... 我不是编码员...

The closest I've found would be something like this? 我找到的最接近的是这样的东西?

How to edit content on pages for Collection Tags in Shopify 如何在Shopify中编辑页面上用于收集标签的内容

...few hours later in theme.liquid I've tried doing the following in the title which seems to work. ...几个小时后,在theme.liquid中,我尝试在标题中执行以下操作,但似乎可行。

{% if current_tags contains 'News' %}
        News page title
        {% elsif current_tags contains 'How To' %}
        how to page title
        {% else %}
      {{ page_title }}{% if current_tags %}{% assign meta_tags = current_tags | join: ', ' %} – {{ 'general.meta.tags' | t: tags: meta_tags }}{% endif %}{% if current_page != 1 %} – {{ 'general.meta.page' | t: page: current_page }}{% endif %}{% unless page_title contains shop.name %} – {{ shop.name }}{% endunless %}
      {% endif %}

I could do something similar for the meta description. 我可以对meta描述做类似的事情。 Just wondering if this is a terrile way to do it, would it cost much page load time? 只是想知道这是否是一种糟糕的方法,这会花费很多页面加载时间吗?

Your solution is not very dynamic. 您的解决方案不是很动态。

There is a few ways you can approach this and make it fully dynamic, so that you don't have to write any code for each additional tag. 您可以通过几种方法使其完全动态,从而不必为每个附加标签编写任何代码。

Here is one example: 这是一个例子:

Create a navigation with Web Address links. 使用网址链接创建导航。 The title will be the tag name and the URL will be title/description. 标题将是标签名称,URL将是标题/描述。

So something like so: 所以像这样:

Linklist Menu: 链接列表菜单:

title.................../ URL...............
This is the meta title / #meta_title_tag1 
This is the meta desc / #meta_desc_tag1 

And in the head section you will have similar code: 在头部,您将具有类似的代码:

{% assign tag_size = current_tags | size %}
{% assign meta_title = current_tags | prepend: 'meta_title_' %}
{% assign meta_desc = current_tags | prepend: 'meta_desc_' %}

{% if tag_size == 1 %}
    {% for link in linklists[settings.meta_nav].links %}
        {% assign url = link.url | split: "#" %}
        {% if url[1] == meta_title %}
            {{ link.title }}
        {% endif %}
        {% if  url[1] == meta_desc %}
            {{ link.title }}
        {% endif %}
    {% endfor %}
{% endif %}

Break Down of the code: 细分代码:

{% assign tag_size = current_tags | size %}

We create the tag_size variable so that we can check if we are on a tag page and if there is only 1 tag, because the user can add a second tag and then our logic won't work. 我们创建了tag_size变量,以便我们可以检查我们是否在标签页上,以及是否只有1个标签,因为用户可以添加第二个标签,因此我们的逻辑将不起作用。 ( But if you like you can get the first tag and apply the meta title and descriptions only for him ) (但是,如果您愿意,您可以获取第一个标签,并仅对他应用元标题和描述)

{% assign meta_title = current_tags | prepend: 'meta_title_' %}
{% assign meta_desc = current_tags | prepend: 'meta_desc_' %}

We prepend a prefix to the current tag in order to check the title and description. 我们在当前标签之前添加前缀,以检查标题和描述。

{% if tag_size == 1 %}
....
{% endif %}

This is the if that checks if the tag is only 1. 如果是, if检查代码是否仅为1。

{% for link in linklists[settings.meta_nav].links %}
...
{% endfor %}

Here we loop all of the links in the navigation menu we created. 在这里,我们循环创建的导航菜单中的所有链接。 Where settings.meta_nav is a link_list field in the Settings Schema of the theme. 其中settings.meta_nav是主题的设置架构中的link_list字段。 You can hard code the navigation handle if you like here, it's your choice. 如果您愿意,可以对导航句柄进行硬编码,这是您的选择。

{% assign url = link.url | split: "#" %}

Here we strip the URL from the "#" that we added. 在这里,我们从添加的“#”中剥离URL。

{% if url[1] == meta_title %}
    {{ link.url }}
{% endif %}
{% if url[1] == meta_desc %}
    {{ link.url }}
{% endif %}

And here is where we check if the current link.title is equal to the prefixed tags we created and if they are, we output their link.url which is the title/description we are looking for. 在这里,我们检查当前的link.title是否等于我们创建的前缀标签,如果link.url ,则输出其link.url ,即我们正在寻找的标题/描述。


All of this can be done with a global section as well if you are looking for a large content and you like to use a textarea instead of a text field. 如果您要查找大量内容,并且希望使用文本区域而不是文本字段,则也可以使用全局部分来完成所有这些操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM