WordPress.org

Forums

[Plugin: AddQuicktag] Is caption adding possible? (2 posts)

  1. acub
    Member
    Posted 5 years ago #

    I was wondering if there was a way to add a caption button that would ask for three things:
    1. {link} = location of image file
    2. {title} = title of image file
    3. {align} = alignment (left|right|center|none)

    with these params it should output:
    [caption caption="{title}" width="200" align="align{align}"]<a href="{link}" title="{title}"><img src="{link}" width="200" alt="{title}" /></a>[/caption]

    of course, for complete functionality it should also ask for width, but since i want all my captions 200px, i don't really need that.

    Now would that be possible?
    I know it cannot be done with your plugin as is.
    I was wondering how the quicktags.js would look for such a button...

    http://wordpress.org/extend/plugins/addquicktag/

  2. acub
    Member
    Posted 5 years ago #

    in case anyone else needs this: i've solved it.
    because i didn't need both [img] and [caption] image, i just modified
    quicktags.dev.js like this (around line 379):

    function edInsertImage(myField) {
    	var myUrl = prompt('quicktagsL10n.enterImageURL', 'http://');
    	if (( myUrl !== 'http://') && ( myUrl !== null)) {
    		var myTitle = prompt('quicktagsL10n.enterImageDescription', '');
    		var myAlign = prompt('Insert image alignment\n( left | right | center | none )', 'left');
    		myValue = ' [caption width="200" align="align'
    				+ myAlign
    				+ '" caption="'
    				+ myTitle
    				+ '"]<a href="'
    				+ myUrl
    				+ '" title="'
    				+ myTitle
    				+ '"><img src="'
    				+ myUrl
    				+ '" width="200" alt="'
    				+ myTitle
    				+ '" /></a>[/caption] ';
    		edInsertContent(myField, myValue);
    	}
    }

    Of course, would have been nicer to have 4 radio-buttons for selecting the alignment, but since I'm not much of a programmer and couldn't find a proper example, they'll just have to type in the alignment. It's way better than having them type the caption/a/img list of commands.
    This is for users who really don't know their way around HTML.

    If anyone has a better idea of how to do this in a more elegant way (plugin-like, so it stands to WP upgrades) I'd be quite happy to hear about it.

    Cheers.

Topic Closed

This topic has been closed to new replies.

About this Topic