[WP] [Ktai Style] “ページ”作成時に画像がリンクになるのを修正する
用途
wordpressの「ページ」機能を使ったページでは<img>タグが<a>タグに変換されてしまうので、直に<img>タグを使える様に簡易的にカスタムする
例
デフォルト仕様
<img src="○○○○.jpg" alt="画像"> と入力すると ↓ [□<a href="○○○○.jpg">画像</a>] と変換される(□はアイコン)
カスタム後の仕様
<img src="○○○○.jpg" alt="画像"> と入力しても ↓ <img src="○○○○.jpg" alt="画像"> のまま変換されないように
ソース
/wp-content/plugins/ktai-style/inc/shrinkage.php
604行目付近
if ( defined('KTAI_SHRINKAGE_DEBUG') && KTAI_SHRINKAGE_DEBUG && is_ks_error($thumb_path)) {
$replace = '[[' . $thumb_path->getMessage() . ']]';
} elseif ($this->image_inline && $thumb_url) {
$replace = $this->image_element($thumb_url, $alt, $attr)
. (preg_match('/has_orig="true"/', $attr_str) ? '[' : '');
$has_image = true;
} else {
$replace = '[<img localsrc="94" alt="' . __('IMAGE:', 'ktai_style') . '" />';
if (! $path) { // link to a image of external sites
$replace .= $this->link_element($src, $alt, $attr);
} elseif (! is_dir($path) && $size = @filesize($path) && $size <= $this->base->get('cache_size')) { // link to the image
$replace .= $this->link_element($src, $alt, $attr);
$has_image = ! is_ks_error($thumb_path);
} elseif ($thumb_path && $thumb_url) { // link to a thumbnail
$replace .= $this->link_element($thumb_url, $alt, $attr);
$has_image = ! is_ks_error($thumb_path);
} else { // no link to images
$replace .= '<font color="' . self::SIZE_EXCEED_COLOR . '">' . $alt . '</font>';
}
$replace .= preg_match('/has_orig="true"/', $attr_str) ? ' | ' : ']';
}
↓
if ( defined('KTAI_SHRINKAGE_DEBUG') && KTAI_SHRINKAGE_DEBUG && is_ks_error($thumb_path)) {
$replace = '[[' . $thumb_path->getMessage() . ']]';
} elseif ($this->image_inline && $thumb_url) {
$replace = $this->image_element($thumb_url, $alt, $attr)
. (preg_match('/has_orig="true"/', $attr_str) ? '[' : '');
$has_image = true;
} else {
//$replace = '[<img localsrc="94" alt="' . __('IMAGE:', 'ktai_style') . '" />';
$replace = '';// ← <img>の要素をまるごと消す
if (! $path) { // link to a image of external sites
$replace .= $this->link_element($src, $alt, $attr);
} elseif (! is_dir($path) && $size = @filesize($path) && $size <= $this->base->get('cache_size')) { // link to the image
$replace .= $this->link_element($src, $alt, $attr);
$has_image = ! is_ks_error($thumb_path);
} elseif ($thumb_path && $thumb_url) { // link to a thumbnail
$replace .= $this->link_element($thumb_url, $alt, $attr);
$has_image = ! is_ks_error($thumb_path);
} else { // no link to images
$replace .= '<font color="' . self::SIZE_EXCEED_COLOR . '">' . $alt . '</font>';
}
//$replace .= preg_match('/has_orig="true"/', $attr_str) ? ' | ' : ']';
$replace .= preg_match('/has_orig="true"/', $attr_str) ? ' | ' : '';//←「]」を消す
}
640行目付近
private function link_element($href, $anchor, $attr) {
$html = sprintf('<a href="%s"%s%s>%s</a>',
$href,
(isset($attr['class']) ? ' class="' . $attr['class'] . '"' : ''),
(isset($attr['style']) ? ' style="' . $attr['style'] . '"' : ''),
$anchor);
return $html;
}
↓
private function link_element($href, $anchor, $attr) {
//$html = sprintf('<a href="%s"%s%s>%s</a>',
$html = sprintf('<img src="%s"%s%s alt="%s">',
$href,
(isset($attr['class']) ? ' class="' . $attr['class'] . '"' : ''),
(isset($attr['style']) ? ' style="' . $attr['style'] . '"' : ''),
$anchor);
return $html;
}
備考
投稿欄からのエントリーについては未検証です。
パケットの問題があるので、特定の用途でない限り全くオススメできません。
