可以在風格的functions.php檔案中,(風格位置: wp-content/themes/)加入以下代碼:
add_filter('wpforo_content_filter', 'wpforo_default_attachment_image_embed', 11); function wpforo_default_attachment_image_embed( $content ){ if( preg_match_all('|<a class=\"wpforo\-default\-attachment\" href\=\"([^\"\']+)\"[^><]*>.+?<\/a>|is', $content, $data, PREG_SET_ORDER) ){ foreach($data as $array){ if(isset($array[1])){ $file = $array[1]; $e = strtolower(substr(strrchr($file, '.'), 1)); if( $e == 'jpg' || $e == 'jpeg' || $e == 'png' || $e == 'gif' ){ $filename = basename($file); $html = '<a class="wpforo-default-image-attachment" href="' . esc_url($file) . '" target="_blank"><img src="' . esc_url($file) . '" alt="' . esc_attr($filename) . '" title="' . esc_attr($filename) . '" /></a>'; $content = str_replace($array[0], $html, $content); } } } } return $content; }
詳情亦可以參看官方原文:
http://wpforo.com/community/how-to-and-troubleshooting-2/uploading-and-embedding-images/
For embed Youtube video, add this to 風格的functions.php檔案中,(風格位置: wp-content/themes/)加入以下代碼::
add_filter('wpforo_content_after', 'wpforo_custom_video_embed', 10);
function wpforo_custom_video_embed( $content ){
$paterns = array();
$paterns[] = "/<a[^><]+>\s*[a-zA-Z\/\/:\.]*youtube.com\/watch\?v=([a-zA-Z0-9\-_]+)([a-zA-Z0-9\/\*\-\_\?\&\;\%\=\.]*)/i";
$paterns[] = "/<a[^><]+>\s*[a-zA-Z\/\/:\.]*youtu.be\/([a-zA-Z0-9\-_]+)([a-zA-Z0-9\/\*\-\_\?\&\;\%\=\.]*)/i";
$content = preg_replace($paterns, "<iframe width=\"100%\" height=\"280\" src=\"//www.youtube.com/embed/$1\" frameborder=\"0\" allowfullscreen></iframe>", $content);
return $content;
}