Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
A poor man's var_dump for the image_send_to_editor() filter in Wordpress. Throw this in your functions.php file and add an image to your post to see what get's passed. Filter it however you want to return the image however you want.
function show_img_vars($html, $id, $caption, $title, $align, $url, $size, $alt) {
// round up all the variables that get passed so we can test them
$vars = "html = $html\n";
$vars .= "id = $id\n";
$vars .= "caption = $caption\n";
$vars .= "title = $title\n"; // this will end up blank no matter what
$vars .= "align = $align\n";
$vars .= "url = $url\n";
$vars .= "size = $size\n";
$vars .= "alt = $alt\n";
// return the normal html output you would expect
$return = $html . "\n";
// add our ad-hoc var dump to the editor
$return .= "<!-- args \n";
$return .= $vars;
$return .= "/args -->";
return $return;
add_filter( 'image_send_to_editor', 'show_img_vars', 10, 9 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment