Add an Option to the Attachment Display Settings to Rewrite Attachment Link
-
I have been banging my head on this for days, which means I’m probably waaaay off course with what I want to do and the best way to go about it.
I have a site where at the bottom of every page are links to downloadable assets (.pdf, .docx, etc.) These links have an icon attached via a css class, and the file size is displayed after the link. These all come together easily enough for me (I have a function that will return the file size from the metadata), but I want my HTML-illiterate client to be able to do these things with no effort at all when they’re adding new assets themselves. Ideally there would be no short tags involved either.
My ideal method would be to have the Admin/Editor define these assets as ‘downloadable files’ from within the Media Library modal which appears when they click the ‘Add Media’ button in the editor. Either they would select a checkbox on the right-side pane or I would add this option to the existing ‘Link To’ drop-down already there. By making this selection, it would write the link into the content editor with my class and metadata appended appropriately. Alternatively it’s acceptable if the method were the same, but no change appeared in the editor, however the page would output the links to the browser in the style I described.
I have already explored the attachment_fields_to_edit and the attachment_fields_to_save hooks and I’m getting nowhere with those. I can make a checkbox appear in the modal, and my meta data is stored but I have no idea how to leverage that to change the uploaded file’s link, and my attempts just break WP.
So I guess I have several questions really:
- I can find several online tutorials on how to add fields and save their data using the attachment_fields_to_edit and attachment_fields_to_save hooks, but can anyone direct me on how to leverage this to change the attachment link in the manner I described?
- If those hooks are not the best solution, does adding an option to the “Link To” drop-down make sense? Are the any known tutorials on customizing that?
- Is there a 3rd option that I’m neglecting?
If it helps, I do know PHP, but not nearly as well as front-end stuff. OOP is definitely above my skill level, but I’m a quick learner (or so I like to think.)
Thank you so much in advance. Cheers.
- The topic ‘Add an Option to the Attachment Display Settings to Rewrite Attachment Link’ is closed to new replies.