When someone creates a post in a custom post type and uploads an image the Link URL box shows it as the attachment URL. What I would like is for it to be the permalink to the post. Is there a way to do it without modifying core files?
Leave a Reply
You must be logged in to post a comment.
Thanks for answering the comments and thanks to @×× ××ת ×תר×× providing the screenshot; now I have a better idea of what you wanted.
Based on what you asked for I think what would be ideal would be for the dialog box to simple generate your preferred URL; that way you don’t have to remember to click. You can accomplish what you are after by using the
'attachment_fields_to_edit'
hook and modifying the sub-elements of the passed array:$form_fields['url']['html']
.You can copy the following code to your theme’s
functions.php
file, or to a.PHP
file for a plugin you might be writing:Here’s what it looks like with the commented-out code so that the full permalink to the attachment post shows:
Here’s what it looks like with the commented-out code so that the full permalink to the attachment post shows:
Note that one caveat is this only works after you have saved the parent post because the permalink is evidently not finalized until then. I’m sure there’s a workaround but I’ll leave that as an exercise for the reader (like my professors used to say…)
P.S. I simultaneously love your domain name, and I feel quite queasy about it at the same time! 😉
On the media uploader, Once an image is uploaded , before you click the “insert to post”
you need to click the “none” button under link url.
here, they say a picture is worth a 1000 words: