Link images to post permalink – custom post types

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:

add_filter('attachment_fields_to_edit','your_attachment_fields_to_edit',10,2);
function your_attachment_fields_to_edit($form_fields,$post) {
  $url = get_permalink($post->ID);

  /* UNCOMMENT THESE LINES IF FOR PARENT POST URL AND NOT ATTACHMENT POST URL
  $url_parts = explode("https://wordpress.stackexchange.com/",trim($url,"https://wordpress.stackexchange.com/"));
  array_pop($url_parts);
  $url = implode("https://wordpress.stackexchange.com/",$url_parts) . "https://wordpress.stackexchange.com/";
  */
  $form_fields['url']['html'] =<<<HTML
<input type="text" class="text urlfield" name="attachments[{$post->ID}][url]" 
       value="{$url}" />
HTML;
  return $form_fields;
}

Here’s what it looks like with the commented-out code so that the full permalink to the attachment post shows:

Screenshot of a Modified WordPress File Upload Dialog with changed URL

Here’s what it looks like with the commented-out code so that the full permalink to the attachment post shows:

Screenshot of a Modified WordPress File Upload Dialog with different URL

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! 😉

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)