To access a page’s title in Shopify Liquid, you can use the page_title variable. For example:
<title>{{ page_title }}</title>
This will output the title of the current page in the <title>
tag of your HTML.
It’s important to note that the page_title
variable is only available on certain pages, such as product pages, collection pages, and blog post pages. It is not available on pages like the homepage or contact page. In these cases, you can use a different approach to set the page’s title.
For example, if you want to set the title of the homepage, you can use the settings.site_title
variable, like this:
<title>{{ settings.site_title }}</title>
This will output the title that you have set for your store in the Shopify dashboard.
You can also set the title dynamically based on the content of the page. For example, if you want to include the name of a collection in the title of the collection page, you can use the collection.title
variable, like this:
<title>{{ collection.title }} | {{ settings.site_title }}</title>
This will output the collection’s title followed by the site’s title, separated by a pipe symbol (|
).
I hope this helps! Let me know if you have any other questions.