Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2021-04-08 06:49:38

agovella
Member
From: Houston, TX
Registered: 2005-05-01
Posts: 65
Website Twitter

Display SEO-friendly file name in img tag?

I give my images proper, SEO-friendly names, however, images always use ID for the src attribute.

Is it possible to use an image name instead of an ID?

For example, instead of this: <img src=“9.jpg” />

We would see this: <img src=“seo-keywords-here.jpg” />

Offline

#2 2021-04-08 06:58:17

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,578
Website

Re: Display SEO-friendly file name in img tag?

If your server is running Apache, you can achieve that aim with the help of an .htaccess RewriteRule, though the url format is very slightly different: see this thread for more info. The same principle could almost certainly be adapted for other server configurations.


TXP Builders – finely-crafted code, design and txp

Offline

#3 2021-04-08 07:38:03

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,250
Website GitHub

Re: Display SEO-friendly file name in img tag?

Yes, that thread is the ticket, but read to the end of the thread to find updates to maniqui’s (clever) solution that don’t need any plugins as you can output everything you need with the built-in <txp:images> and <txp:image_info> tags. Gocom’s solution is also great.

Maybe we could one day adopt something like this idea in core so people have the option to display optional image names? But we’d need a way to do it for Nginx too before we even consider something. Or find another way of doing it by stripping off the image name when we process the tags. Or just to hell with it and output both id and name all the time.

Last edited by Bloke (2021-04-08 07:40:23)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#4 2021-04-08 08:39:38

phiw13
Plugin Author
From: Japan
Registered: 2004-02-27
Posts: 3,058
Website

Re: Display SEO-friendly file name in img tag?

Bloke wrote #329713:

Or just to hell with it and output both id and name all the time.

This :-) aka <img src="/images/13-cute-seo-name.webp" alt="other cute keyword" >. Maybe as part of the revamp of the back-end image handling?

Backwards compatibility etc, though.


Where is that emoji for a solar powered submarine when you need it ?
Sand space – admin theme for Textpattern

Offline

#5 2021-04-08 08:47:44

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,250
Website GitHub

Re: Display SEO-friendly file name in img tag?

phiw13 wrote #329716:

This :-) aka <img src="/images/13-cute-seo-name.webp" alt="other cute keyword" >. Maybe as part of the revamp of the back-end image handling?

It has occurred to me now might be a nice time to do that since we’re making other image-related changes. Leave it with us.

And yeah, backwards compatibility is always a priority if we can maintain it, so we would need to permit both. That’s why I was thinking of stripping it off at the tag processing level if we can. So you could write 22-life-the-universe-and-everything.jpg or 22-bob-the-builder.jpg or just 22.jpg and it’ll only ‘see’ the latter and handle it. Not sure. Will have to see what’s possible.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#6 2021-04-12 02:33:04

agovella
Member
From: Houston, TX
Registered: 2005-05-01
Posts: 65
Website Twitter

Re: Display SEO-friendly file name in img tag?

Amazon does that with product URLs. You can keep the book title, or delete it and leave just the ID and it resolves correctly.

Last edited by agovella (2021-04-12 03:00:48)

Offline

Board footer

Powered by FluxBB