Rename file upload link to include part of the filename, before the extension?

This topic contains 5 replies, has 3 voices, and was last updated by  Louis Nel 8 years, 8 months ago.

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket
  • Author
    Posts
  • #378647

    Louis Nel
    Expired Member
    Post count: 6

    Hi

    I created custom File Upload fields for restaurants to upload their menus. I do not want to display the filename of the document, and have gotten a way around that to say something like “Download the Summer menu”, but there are so many different menu options I will have to create endless amount of custom fields to show the Breakfast menu, Lunch, Dinner, Bar Mitzvah menu etc.

    Is there a way I can name the link after the first part of the pdf filename for example” Download the Summer Menu” for the Summer.pdf file?

    Thank you.

    #378687

    Paolo
    Site Admin
    Post count: 31211

    Hi Louis,

    I’m really sorry, but I’m not sure I understand the question. Can you please clarify?

    In the mean time i flagged your question for the developers, maybe they’ll better understand your question and reply.

    Let us know,

    Thanks

    #378713

    Louis Nel
    Expired Member
    Post count: 6

    Hi

    Thank you for getting back to me so quickly.

    At the moment when I upload a file called Summer_Menu.pdf under the “File Upload” field, it will display a link called Summer_Menu.pdf . That is ok, but if the file is called 345_Sum20170517.pdf it is a bit messy. Putting the code below into the functions.php , I can get it to display that particular field with html variable “winter_menu”, as “Download the Winter Menu”

    // Replace ‘winter_menu’ in “geodir_show_geodir_winter_menu” with the html variable of your custom field
    add_filter(“geodir_show_geodir_winter_menu”,”myTheme_change_menu_title”, 10,2);
    function myTheme_change_menu_title($html, $variables_array){
    if($parts = explode(‘target=”_blank”>’,$html)){
    $html = $parts[0].’target=”_blank”>Download the Winter Menu</div></div>’;
    }
    return $html;
    }

    Because there are so many types of menus, I cannot create a field for each one, because everybody in the restaurant business has their own menu type. I would like to get the link name to be derived from the pdf file name. That means the pdf file name will have to be properly formatted, but that will just have to be the case.

    If the file is called Bar_Mitzvah.pdf I want the link to be displayed as “Download the Bar Mitzvah Menu”. If the file is called Breakfast.pdf I want the link to be displayed as “Download the Breakfast Menu”.

    Is there a way this can be done?

    Kind regards

    #378828

    Paolo
    Site Admin
    Post count: 31211

    Hi again,

    Got you now, I’m not 100% sure it’s feasible, but with the right code it should.

    I asked to Stiofan to let us know what he thinks, he didn’t reply today because he’s traveling, but he’ll let you know tomorrow 1st thing.

    Thanks

    #378952

    Stiofan O’Connor
    Site Admin
    Post count: 22956

    Would it not be simpler to just have Download the menu: savoy_summer_menu.pdf
    That way both users and owners have an easy time of it and formatting is unlikely to break, the other way can be done but relying on users might result in things like “Doenload the adf8adsf Summer menu”

    Stiofan

    #379057

    Louis Nel
    Expired Member
    Post count: 6

    Dear Stiofan

    Thank you for your help. Currently the answer you gave is the option most people would use, but then you still have people giving files unsexy names, and the “pdf” bit at the end does not make it better.

    I have the situation where people have up to four menus. I would have to create upload fields that would say “Download Menu no.1”, “Download menu no.2” because there are just so many types of menus.

    In the attachment four menus are displayed in their own tab on a unrelated directory website, within a tab. The tabs have the menu’s unique name on them. These are html fields which would be fine. Currently I can create html fields, that can be in their own tabs, but they would still have to have generic names on the tabs.

    The suggestion for multiple file uploads here ( https://wpgeodirectory.com/support/topic/multiple-files-into-the-same-custom-field/ ) is a possibility with some work.

    Thank you for your help.

Viewing 6 posts - 1 through 6 (of 6 total)

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket
20% Discount Offer
Hurry! Get your 20% discount before it expires. Get 20% Discount