使用 WordPress 的人,难免会在文档中插入图片,如何设置插入图片的默认选项呢?比如插入图片的大小、是否链接到图片本身、图片对齐方式
function default_attachment_display_settings() { update_option( 'image_default_align', 'center' );//居中显示 update_option( 'image_default_link_type', 'file' );//链接到媒体文件本身 update_option( 'image_default_size', 'full' );//完整尺寸 } add_action( 'after_setup_theme', 'default_attachment_display_settings' );
wordpress 上传图片默认的 a 标签怎么去除?
我们只需要依葫芦画瓢,将上述代码中的
update_option( 'image_default_link_type', 'file' );//链接到媒体文件本身
替换为:
update_option( 'image_default_link_type', 'none' );//不链接图片本身
其实小雨也发现一个比较简单的办法:
在编辑文章的时候 选择插入多媒体按钮,然后按下图选择 图片链接到选择无即可,以后默认插入图片的时候就没有 a 标签了
当然了,有的人并不喜欢 wordpress 为图片自动添加的 class 包括 width、height 等
add_filter( 'post_thumbnail_html', 'auto_remove_images_attribute', 10 ); add_filter( 'image_send_to_editor', 'auto_remove_images_attribute', 10 ); function auto_remove_images_attribute( $html ) { //$html = preg_replace( '/(width|height)="\d*"\s/', "", $html ); $html = preg_replace( '/width="(\d*)"\s+height="(\d*)"\s+class=\"[^\"]*\"/', "", $html ); $html = preg_replace( '/ /', "", $html ); return $html; }
按需选择吧!
你可能对这些文章感兴趣:
- WordPress异步发送邮件通知实现
- 万网虚拟主机更改固定链接失败的终极办法
- WordPress加速:只显示上传到本文章中的图片
- 提示为WP_Widget调用的构造方法已自版本4.3.0起废弃的解决办法
- 利用Robots.txt优化你的WordPress站点
- WordPress添加百度站内搜索(适合所有网站)
- WordPress插件推荐:实现登陆后可见
- WordPress个人博客主题推荐(像书一样的Abook)
- 今天发现站长工具site博客首页位置不在第一了
- WordPress插件推荐:jQuery Image Lazy Load wp
- 靠个人博客赚钱靠谱么?
- WordPress免插件实现七牛免费图床
- [已失效]WordPress插件推荐:wp2sinablog优化版
- xiu主题修改社交字符
如有疑问,请前往问答中心反馈!
反馈