WordPress在编辑文章插入图片的时,默认为左对齐,可以通过添加以下代码到主题的functions.php 文件最后一个?>的前面。
/**
* WordPress 设置图片的默认显示方式(尺寸/对齐方式/链接到)
* https://www.wpdaxue.com/image-default-size-align-link-type.html
*/
add_action( 'after_setup_theme', 'default_attachment_display_settings' );
function default_attachment_display_settings() {
update_option( 'image_default_align', 'center' );//居中显示
update_option( 'image_default_link_type', 'file' );//连接到媒体文件本身
update_option( 'image_default_size', 'full' );//完整尺寸
}
代码中有三个选项,它们各自的参数如下,你可以根据自己的需要进行设置:
image_default_align,图片的对齐方式
- left:左对齐
- right:右对齐
- center:居中对齐
- none:无
image_default_link_type,图片的链接到
- file:媒体文件本身
- post:附件页面,也就是图片所在文章地址
- custom:自定义URL
- none:无
image_default_size,图片的尺寸
- thumbnail:缩略图尺寸
- medium:中等尺寸
- full:完整尺寸
原文链接:https://www.pengjy.com/255.html,转载请注明出处。
评论0