Trying to spread the product title over 2 or 3 lines as this looks alot nicer. People told me to use metafields. I now have created all the metafields but i still don’t understand how I can use the metafields as title.
Hello @Bramm
it needs to modify liquid and replace the {{ product.title }} with above mentioned metafields.
so please find the in the theme where {{ product.title }} and replace that.
Open the Liquid file for the product page where you want to display the title with line breaks. This could be product.liquid or a similar file.
Find the section of the file where the product title is displayed. This will typically be wrapped in an HTML tag like <h1> or <h2>.
Replace the existing code that displays the product title with Liquid code that references your metafields and adds line breaks. For example, let’s say you have created two metafields called Line 1 and Line 2. You can use the following code to display the title with two lines:
This code uses the {{ }} Liquid tags to reference the values of the Line 1 and Line 2 metafields. The <br> HTML tag is used to add a line break between the two lines.
Not sure I agree with that recommendation to move each part into a metafield. I am a huge metafield fan but this sounds like extra work.
Liquid is able to look at a string and split it into parts. For example it could take “Dior Sauvage Eau de Toilette” and split it into two by looking for “Eau de Toilette” (Eau de Parfum etc). This would give you an array with:
Dior Sauvage
Eau de Toilette
If “Dior” is already added as the vendor then you could also use that to split out the first part. This would give you your three components.
Dior
Sauvage
Eau de Toilette
Since you already have to add Liquid code to show the metafields this feels like a much better and easier long term management. It would require that the vendor field value matches the first part of the title exactly.
Now that said, if you must use metafields where are you replacing it? On a product page - a collection page - somewhere else? The location of the code you need to change will differ based on the theme and where you’re replacing it.