3
當您編輯頁面內容時,在TinyMCE編輯器上方有一個「添加媒體」按鈕。該鏈接將該文件的鏈接插入到頁面內容中。如何更改「添加媒體」上插入的html代碼?
如何更改基於文件類型/ MIME類型插入的HTML代碼?
當您編輯頁面內容時,在TinyMCE編輯器上方有一個「添加媒體」按鈕。該鏈接將該文件的鏈接插入到頁面內容中。如何更改「添加媒體」上插入的html代碼?
如何更改基於文件類型/ MIME類型插入的HTML代碼?
您需要使用過濾器media_send_to_editor
。
add_filter('media_send_to_editor', 'so_6884350_send_to_editor', 10, 3);
function so_6884350_send_to_editor($html, $send_id, $attachment)
{
/* Manipulate $html result */
return $html;
}
$html
是將在您的帖子中插入的代碼。類似於<a href='http://example.com/wp-content/uploads/2012/11/README.rtf'>README</a>
$send_id
是正在插入的附件的ID。用它來獲取有關附件的信息,即get_post_mime_type($send_id);
。
$attachment
是具有以下結構的陣列:
array(
['menu_order'] =>
['post_title'] => 'README'
['post_excerpt'] =>
['post_content'] =>
['url'] => 'http://example.com/wp-content/uploads/2012/11/README.rtf'
)