WordPresの画像をエディタに追加する際 HTML ではなく Markdown にする。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function change_image_insert_code($html){ | |
$rootURL = (empty($_SERVER['HTTPS']) ? 'http://' : 'https://').$_SERVER['HTTP_HOST']; | |
preg_match('/src="([a-z\d:\/.\-\_%~^]+)/i', $html, $src); | |
$src = str_replace($rootURL, '', $src[1]); | |
// error_log($html, 3, '/var/www/html/dump.log'); | |
preg_match('/alt="([^"]+)"/', $html, $alt); | |
$alt = empty($alt[1]) ? '' : $alt[1]; | |
preg_match('/title="([^"]+)"/', $html, $title); | |
$title = empty($title[1]) ? '' : $title[1]; | |
return $title ? "" : ""; | |
} | |
add_filter('image_send_to_editor', 'change_image_insert_code', 10); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment