Support » Plugin: Media Library Assistant » Link to slug

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author David Lingren


    Thanks for your question. I am not sure I understand what you mean by “add slugs to media items” and “link to the string-based url“.

    I believe you are referring to the “Name/Slug” field in the Quick Edit area, which is shown on the Media/Edit Media screen as a meta box labeled “Slug”; is that right?

    If that’s right, then you may not understand how WordPress uses the content of the “slug” field. The slug is used to identify each post, page and attachment (media item) in the database. It forms part of the URLs (permalinks) WordPress generates, and is usually derived from the Title. A suffix is added if necessary to make the slug value unique. Slug values are “sanitized” to make sure they can be used as one part of the URL/permalink; that may be the “string-based url” you refer to. You might find this earlier topic is similar to what you want:

    link to the pdf on the title and the icon

    If you can give me an example or two of the slugs you have and the links you want to generate I can be more helpful. Any additional information you can give would be great. I am confident MLA can give you the results you need.

    OK, So I might have an attachment that I have set a slug for. The slug is called ‘bird’ for example. So, if I set this, and then go to, I get my attachment page just fine.

    However, if I put the MLA shortcode in my tag archive, for example, so it outputs all images tagged with that tag, This links a string, like this:

    It still works; I can still see the same attachment page. However, I would like it to link to the slug, and not the string.

    Now, I have noticed that if I have an image attached to a post somewhere, that particular image in my gallery will link to the slug; however, it will link like this: I don’t really want this either, because I want the image to be in the context of whatever filter I”m using (like tag, or category) and not in the context of a blog post in which I may have happened to include the image at one time.

    Thanks for your help.

    Sorry, I know I made this complicated. I went ahead and launched the site you can see what I’m talking about:

    OK, take a look at this page. This is using your mla_gallery code in the category.php template to show all images categorized as ‘found’. Note that most thumbnail links are a string; however, the first image was attached to a post, now deleted, and it uses slugs. Now, when you click on it, it returns a 404 error, because I deleted the post to which that image was attached.

    Like I mentioned, I would like them all to return slugs; however, I am starting to get from your documentation on custom navigation, that I need to pass some variables to the string in the URL for that to function properly. So, if this is necessary, I can live with the string and not the slug—I just want it to be uniform.

    Plugin Author David Lingren


    Thank you for the additional information; very helpful.

    The first image in your example gallery could be linked to a post that’s still in the trash; is that possible?

    MLA uses a WordPress function, wp_get_attachment_link, to generate the links in an [mla_gallery]. This function gets the URL from another WordPress function; get_attachment_link. The Codex Function Reference page says:

    Return value

    Under a “pretty” permalink structure, the function returns something like

    Under the default permalink structure — or if WordPress can’t construct a pretty URI — the function returns something like, where n is the attachment ID number.

    You can trace through the source code of that function to see what it does. You could hook the filter provided at the end of that function and replace the link, but that’s probably not necessary.

    Try adding the mla_link_href parameter to your shortcode. You can use something like:


    to always go to the attachment page using the slug. I am not entirely sure what you mean by “the context of whatever filter I’m using” but if you’re working in PHP code you can use sprintf() to compose anything you need and then insert the result into your shortcode parameters. As long as you put {+slug+} in the right place you’ll get the right URL for each item.

    I will leave this topic unresolved until I hear back from you, to make sure I understood your goal and the suggestion works for you.

    Try adding the mla_link_href parameter to your shortcode. You can use something like:


    to always go to the attachment page using the slug.

    This solved my problem. Forget about the other comments about the context, or the deleted post. It’s irrelevant. Your solution worked great on the page. Thank you.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Link to slug’ is closed to new replies.