• 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.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    For your situation, I would be inclined to add a metabox to the post editor to contain the downloadable asset references. The file URLs could be stored as an array in post meta.

    Then your post template would be modified to grab this array and loop through each file in the array. The loop could dynamically determine the file type and generate the required HTML links, classes, etc. for each file.

    The concept is very similar to adding files as email attachments, so shouldn’t confuse unsophisticated clients too much. I’m not sure of many of the particular details about doing something like this, but I’m sure it is doable without breaking anything.

    Even if you don’t like my idea, I think storing the data in post meta and dynamically generating the links and classes with your post template is the best way to handle the data and output, regardless on how you choose to implement the backend user interface.

    Moderator bcworkz

    (@bcworkz)

    Argh! I double posted due to a connection glitch, ignore this post.

    Thread Starter wisefool99

    (@wisefool99)

    Thanks bcworkz. I will look into that.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Add an Option to the Attachment Display Settings to Rewrite Attachment Link’ is closed to new replies.