购买测速网主题的一些小白级用户时常会问一个问题,就是在添加媒体里添加的图片显示出来过小,但是不能居中,这时需要截图给用户讲解下设置方式,其实静下来想想大多数用户的需求其实很简单就是正常大小,居中显示。所以,今天测速网给大家分享一段可以设置默认图片插入方式设置的代码。今后测速网主题的升级版都会添加此功能。来增强用户体验度。
比如我们设置插入图片的尺寸默认为完整尺寸,链接到媒体文件本身,并居中显示,那么我们只需要将下面的代码添加到主题的 functions.php 文件最后一个?>的前面即可:
area data-settings="dblclick" readonly >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' ); //完整尺寸}area>123456add_action( 'after_setup_theme', 'default_attachment_display_settings' );function default_attachment_display_settings() {update_option( 'image_default_align', 'center' ); //居中显示update_option( 'image_default_l
ink_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:完整尺寸