Support » Plugin: Media Library Assistant » single image short code

  • Resolved Mike


    Congrats on the great plugin!

    BTW did you know that in 3.6 the ID3 meta data library is being added which will parse meta data for audio and visual media in addition to images?

    One question:
    Is there a trivial way to construct a short code for just one image (never mind the style) or is it just easier to create a bare bones style and markup template for an mla_gallery?

    I am trying to leverage the goodness of your API that’s available through a short code as opposed to just adding a link through the “Add Media” method.


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



    Thanks for the good words, the 3.6 tip and for the question.

    The easy way to construct an [mla_gallery] for a single image is to use the ids= parameter, which takes one or more attachment ID values. You can create the shortcode directly if you know the ID value (it’s in the Media/Assistant screen table) or you can use the WordPress Media Manager (“Add Media”) popup; use the “Create Gallery” tab, pick the image you want, “Create a new gallery” and “Insert gallery”. Once the gallery is in your post/page, click the “Text” tab in the upper-right corner of the editor panel, change the shortcode from [gallery ids="XXX"] to [mla_gallery ... ] and add all the other API goodness you need.

    Let me know if you have any problems or further questions about the shortcode.

    I am currently testing the WordPress 3.6 beta version and putting the finishing touches on an MLA upgrade (1.30) which will make all that great new audio/video metadata available in the [mla_gallery] shortcode and on the Media/Assistant screen. Keep your eye out for the next upgrade and let me know what you think.

    Thanks for using the plugin!

    Thanks David. Sorry, I wasn’t clearer. I already figured out most of this.

    My problem is controlling what is inside the markup.
    If I use this

    [mla_gallery ids="398" mla_style=none size="full" link="file"]

    and this markup


    I get this…

    <a href="image_url" title="image_base_name"><img width="xxx" height="xxx" src="image_url" class="wp_size" alt="image_base_name"></a>

    How can I control in a more granular way what gets replaced?
    I see many options. Some I see come from meta data listed in the Assistant Library.
    I want to directly control width, height, class with the shortcode.
    I also want to breakdown the image_url to filepath and filename.
    Instead of [+link+] will the other attachment-specific substitution parameters for markup templates work?


    Another sorry – I was editing the previous comment and the time expired on it.
    Please ignore it.

    My problem is controlling what is inside the markup.
    I am using this:

    [mla_gallery ids="my_attachment_ID" mla_style=none size="full" link="file"]

    and this markup

    <a href="[+site_url+]/files/[+file+]"><img src="[+site_url+]/files/[+file+]" id="[+attachment_ID+]"></a>

    Is there any way of passing a width/height or class through the short code to inside the img tag? I want the user to be able to specify this per image. Or should I add a style to an enclosing div or figure block?

    Also, I am going to need to replace [+site_url+]/files/ with an alternative path for a custom export process. I figured I would add a filter to the short code for [+site_url+] but the /files/ bit confuses me. Is there a parameter for the whole URL apart form the file name? Perhaps the problem here is I am using a multisite created before 3.5 that still has blogs.dir and doesn’t use Yearmonth?


    Plugin Author David Lingren



    Thanks for the additional information; I’m sure you can accomplish your goal.

    The Gallery Display Style and Gallery Display Content parameters give you a lot of control over gallery content without using custom templates, but it sounds like what you want is not really a gallery at all. Your example includes mla_style=none, but I don’t see an mla_markup= parameter to replace the default template; are you using a custom markup template? If not, where are you putting your <a href="[+site_url+] ... markup?

    Let’s assume you’re using a custom markup template (let me know if you need tips an setting one up) called “customlink”, and you’ve added mla_markup=customlink to your shortcode. The markup you want goes in the Item: portion of the template.

    Much of what you need can be found in the Attachment-specific substitution parameters for markup templates. For example, width and height are available as [+width+] and [+height+]. However, when you say:

    Is there any way of passing a width/height or class through the short code to inside the img tag? I want the user to be able to specify this per image.

    do you mean you want to use a different height and width, i.e., resize the image? If that’s the case, you want the Field-level Markup Substitution Parameters instead. With these, you can pass anything you need through the shortcode to the markup inside your template. For example, change your shortcode to something like:

    [mla_gallery ids="my_attachment_ID" mla_style=customlink mla_markup=customlink my_path="" my_width=175 my_height=235]

    and your Item: markup to:

    <a href="[+query:my_path+][+file+]"><img src="[+query:my_path+][+file+]" id="[+attachment_ID+]" width=[+query:my_width+] height=[+query:my_height+]></a>

    The query prefix lets you pass anything from the shortcode to the markup; just be careful to choose unique parameter names.

    That should get you going. Let me know if it’s unclear or if you have problems or other questions.

    By the way, your custom markup template must contain something in the Open:, Row Open:, Row Close: and Close: elements. If not, it won’t be accepted and the default template will be used instead. You can add a simple HTML comment to each part. I consider this a plugin defect and I will fix it in the next release.

    Thanks David.

    Yes I created a custom markup template that I used as the default.
    I just had an Open (div), Item (in previous message), Close (/div). I don’t need any rows because there is just one photo.
    It worked fine, so maybe it’s a feature LOL.

    At this point, I am just seeing what I can do. The real work comes in about a week.

    Your suggestion will solve my problem.
    Looking forward to seeing the new version.


    Plugin Author David Lingren



    It’s good to hear you’ve got what you need. In the process of responding to your question I have found and fixed a couple of defects in the MLA plugin: 1) empty template parts are now handled correctly, 2) substitution parameters with the “query” prefix are now processed in all template parts and 3) “none” can be specified as the default style template. All of these fixes will be in the next release.

    Thanks again for your part in identifying these defects and for your “single image” shortcode idea, which hadn’t occurred to me. Feedback like this is a big part of improving the Media Library Assistant.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘single image short code’ is closed to new replies.