如何将自动类添加到wordpress上传媒体

时间:2017-03-28 18:34:56

标签: html wordpress

如何在帖子中将新课程添加到新的wordpress上传项目?

enter image description here

如何从自动添加:

<a href="mysite.pl/wp-content/uploads/2017/03/upload file name.pdf" class="fileuploadclass">upload file nameV</a>

类= “fileuploadclass” ?

1 个答案:

答案 0 :(得分:0)

只需在当前主题function.php文件中粘贴以下代码即可。

if ( ! function_exists( 'auto_custom_class_add_for_media_attchment' ) ) :

    function auto_custom_class_add_for_media_attchment( $html, $id ) {

        $attachment = get_post( $id );
        $mime_type = $attachment->post_mime_type;

        // Here i added if condition only for pdf mine type, you can use whatever mime_type you require or remove condition for all.
        if ( $mime_type == 'application/pdf' ) {
            $src = wp_get_attachment_url( $id );
            $html = '<a class="fileuploadclass" href="'. $src .'">'. $attachment->post_title .'</a>';
        }

        return $html;
}
endif;
add_filter('media_send_to_editor', 'auto_custom_class_add_for_media_attchment', 20, 3);