Post URL Dynamic Link wrong value when querying attachment

Hey there,

according to my first post here i think i found another problem when using the post type: attachment:

When Linking to the POST URL it seems that it uses the post-title as link option.

Bildschirmfoto 2023-07-21 um 11.48.18

Cheers
Wolfgang

Hello @Wolfgang,

Thanks for the report.
I’m not quite sure I understand the issue at hand here, so please bear with me.

In my understanding of it, the Post URL link will always get you the “pretty” structure for the attachment. In the eventuality you want the direct link to the file (and not the page), then wp_get_attachment_url() would be the way to go here.

We don’t currently offer it, but it seems like we should.

Cheers,

Hey @Louis ,

sorry for the late reply.

Well thats probably a question of how defining the “Post URL” :slight_smile:
In my opinion the Post URL of an attachment would be the whole URL to that attachment, including the “months/day” part in the URL.

Just to clarify, the following scenario:
Base-URL: https://example.com
Image-Title: placeholder
Attachment-URL: https://example.com/wp-content/uploads/2023/24/placeholder.png

What I would expect to be the Post-URL would be the Attachment URL in that scenario inside the builder, probably it is also easier to understand for users, since they are used to use “Post URL” most of the time.

What I get, when using the POST-URL parameter is the following-link: https://example.com/placeholder

Which is, in my opinion, confusing for the user and leads to mistakes.

In my opinion, internal processing the POST-URL and outputting the correct URL to the attachment would be a more intuitive way than providing the option to link to the attachment-url instead, what do you think?

Cheers
Wolfgang

Hello @Wolfgang,

Thanks for clarifying your point of view here.

This is a rather delicate one in my opinion. What you suggest would directly go against how WordPress has built relationships here, since the post URL of a media (or any other really) item should be the frontend facing page, not the direct link to its source.

This is exactly how get_permalink() functions, requiring you to go with wp_get_attachment_url() instead.
I’m fine with modifying the behaviour of Post URL internally, but I know that I would personally be put off by it since it’s moving the user outside the website (in a way).

Attachment URL was added in 1.2.9.8, but nothing is set in stone.

Edit: Just to add, the Post URL provided for attachment is perfectly correct and valid, as provided by WordPress.

Cheers,

Hey @Louis ,

thanks a lot for the implementation. I think with your explanation in mind it is fine to go that way. My point was just, that in the days of lightboxes etc. the Attachment Page itself is probably never really used. At least I’ve never used it :-D.

But your implementation gives us the most flexibility and I guess those user who really query after media types will know that they have to choose another option for the link!

Thanks a lot, as always, for your very fast implementation/fix! :wink:

Cheers

1 Like