WordPress 4.1版本开始引入了一个新的filter,最终提供了一种简单的方法来添加异步/延迟属性。 apply_filters(‘script_loader_tag’, string $tag, string $handle, string $src); 具体用法: function add_async_attribute($tag, $handle) { if ( ‘my-js-handle’ !== $handle ) return $tag; return str_replace( ‘ src’, ‘ async=”async” src’, $tag ); } add_filt…
WordPress默认方法输出内容时,会为编辑器内换行的内容自动加上<p>标签。 如果想去掉这个功能,可使用 remove_filter( ‘the_content’, ‘wpautop’ ); 而有时,例如用了$post->post_content会使这个功能失效,若想还原,可这样写 $content = $post->post_content; $content = wpautop( $content ); 同理可处理摘要the_excerpt()及评论内容comment_text().
How to use it Themes define a subset of core-provided starter content using add_theme_support() – let’s look at a breakdown of how Twenty Seventeen does things. In its setup function hooked to after_setup_theme, we see an array with collections of widgets, posts (pages), attachments, options, theme …
WordPress的Widget小工具是个非常实用的功能,它让非技术型WordPress用户也可以根据自己对版面的需求轻松定制主题,WordPress无数的widgets让用户得以尽情发挥自己的创意。 在很多人的意识里,widget就是出现在侧边栏的小工具,不过实际上它可以出现在主题的任何地方。 这篇文章我们就来看一下怎样用简单的步骤让主题的其它版块也支持widget。 最后还会送上几个widget使用技巧。 第一步 在当前主题的functions.php文件里添加下面这段代码: if (function_exists(‘register_sidebar’)) { register_sideb…
add_theme_support() 用于在我们的当前使用的主题添加一些特殊的功能,函数一般写在主题的functions.php文件中,当然也可以再插件中使用钩子来调用该函数,如果是挂在钩子上,那他必须挂在after_setup_theme钩子上,因为 init hook 对于一些功能来说,已经太迟了. 用法 <?php add_theme_support( $feature ); ?> 参数 $feature (string) (必须) 需要添加特殊功能名称,可以是以下参数: ◆ ‘post-thumbnails’ —– 增加缩略图支持 ◆ ‘automatic-feed-li…