Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End How to modify the WP attachment properties

  • This topic is empty.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #144297
    Josh
    Participant

    Hey all,

    I’ve periodically done searches on this but I’ve come up empty handed. I’ve been hunting for a way to add a little class selection dropdown from the WordPress file attachment screen.

    I can seem to get metaboxes added to the media edit screen just fine, but in the end it’s too many steps to realistically think a client is going to drill into each attachment after they’ve added it.

    What I’m looking to do is be able to upload an image, and then before I add it to the page/post, you can choose from a list of a few different style types (border, shadow, tilted, etc). Has anyone manage to get anything introduced in the media upload area like that?

    #144325
    chrisburton
    Participant

    I wonder if it would be easier for your client to add a specific name to the image file when they upload it? You could apply a class that way.

    #144606
    chrisburton
    Participant

    What do you mean the additional task to rename files? They should be renamed before uploading to WordPress.

    You could use jQuery but I meant through PHP. Let me try to explain in “english code”:

    First, let’s say you require the client to use image filenames like so: shadow1.png, shadow2.png, border1.png, etc.

    At this point you would need to find and strip the numeral on the filename.

    After that, use an if statement to apply a class.

    #144624
    Alen
    Participant

    Create WordPress Shortcode to wrap the image and add a class so you can style it with CSS.

    In functions.php

    function wrap_image_with_fx($atts, $content = null)
    {
    extract(shortcode_atts(array(‘type’ => ‘none’), $atts));
    return ‘<span class=”‘.$type.'”>’.$content.'</span>’;
    }
    add_shortcode( ‘imgfx’, ‘wrap_image_with_fx’ );

    To use:

    [imgfx type="border"] /* insert image here */ [/imgfx]

    This will produce output:

    <span class="border"><p><img src=""></p></span>

    Whatever you pass in as type, will be used as a class.

    Hope that helps.

Viewing 4 posts - 1 through 4 (of 4 total)
  • The forum ‘Back End’ is closed to new topics and replies.