首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往
您找到你想要的搜索结果了吗?
是的
没有找到

WordPress 技巧:优先执行 Shortcode,移除 Shortcode 中自动添加的 br 和 p 标签

我们在使用 WordPress Shortcode API 开发插件的时候,有个比较麻烦的问题,就是 WordPress 会自动在 shortcode 内添加 br 或者 p 标签,这样可能会打乱你的原先预想的...造成这个问题的原因是 WordPress 默认的日志内容处理流程中,wpautop(将回车转换成 p 或者 br 标签的函数)是在 Shortcode 前面运行的。...这样调整顺序之后,你的 shortcode 里面的内容,就不会有自动添加的 p 或者 br 标签,但是如果 shortcode 中部分的内容你又需要一些 p 或者 br 标签用来换行的话,你需要自己手动在自己...shortcode 处理程序中添加 wpautop 来处理了: function bio_shortcode($atts, $content = null) { $content = wpautop...' '; } add_shortcode('bio', 'bio_shortcode');

58520

Shortcake:给 WordPress Shortcode 添加编辑界面

Shortcake 是一个新的 WordPress 插件,他可以让 WordPress 开发者非常容易给 Shortcode 添加编辑界面,用户编辑 Shortcode 的内容和属性。...Shortcake 使用效果 下图就是使用 Shortcake 之前,编辑 Shortcode 的界面: 使用了 Shortcake 之后,整个 Shortcode 就可以点击: 点击 Shortcode...就可以编辑这个 Shortcode 的内容和属性: 让你的 Shortcode 支持 Shortcake 假如你定义了一个 pullquote 的 Shortcode,它有内容,还一个名为 source...的属性: add_shortcode( 'pullquote', function( $attr, $content = '' ) { $attr = wp_parse_args( $attr...php return ob_get_clean(); } ); [/code] 我们就可以使用下面的代码给这个 shortcode 注册它的 UI: [code] shortcode_ui_register_for_shortcode

21920

WordPress 技巧:使用 Shortcode 投放 Google Adsense 广告

请示我们可以使用 WordPress 的 Shortcode 来投放 Google Adsense 广告,非常方便。首先简单来了解下什么是 Shortcode。...什么是 Shortcode Shortcode API 是 WordPress 2.5 之后新增的一个功能,简单的说就是事先定义一组的函数,由此生成对应的一个简单的短代码,然后在内容的正文中的任何地方插入这个短代码...更详细信息可以参考: WordPress Shortcode 介绍和详细使用 使用 Shortcode 投放 Google Adsense 广告 把下面的代码保存到你当前的主题的 functions.php.../ Description: 使用 Shortcode 投放 Google Adsense 广告 Version: 0.1 Author: Denis */ add_shortcode('adsense...', 'adsense_shortcode'); function adsense_shortcode($atts) { extract(shortcode_atts(array( 'type' =

56110

WordPress 技巧:只有指定的 Shortcode 存在时才载入相关脚本文件

WordPress 3.6 版本增加了一个新的函数 has_shortcode(),这个函数的主要功能就是检测指定内容里是否存在指定的 Shortcode 使用,带来的好处就是只在有使用指定 Shortcode...可以点击 has_shortcode() 查看函数的详细介绍,这里着重讲解下使用方法,把下面的代码插入 functions.php 文件里即可 function wpjam_shortcode_scripts...(){ global $post; if( has_shortcode( $post->post_content, 'your-shortcode') ){ wp_enqueue_script...( 'whatever');//检测到有使用短码后需要做的事,大家随意 } } add_action( 'wp_enqueue_scripts', 'wpjam_shortcode_scripts'...('has_shortcode') AND has_shortcode( $post->post_content, 'your-shortcode') ){ wp_enqueue_script(

20120

WordPress 创建简码-建立自定义短码显示文字及图片

WordPress shortcode 在网页设计时是非常弹性的功能,当需要在特定位置加入想要呈现的内容,却受限于网站主题框架无法以内建编辑器或区块小工具完成时,就可以选择自行创建shortcode 函式定义想要显示的内容...,只要在HTML 区块中加入shortcode ,就能够在网站主题不支援编辑的位置显示特定文字或图片,本篇文章分享的shortcode 函式相当简单,只需按照步骤就能够完成 使用add_shortcode...函数 第一步:在下方的函式中,dh_first_shortcode 是可以自定义的名称,但要注意如果有更改,函式结尾处的add_shortcode 内容也必须要替换成一样的名称。...而这段函式所代表的意义就是定义当dh_first_shortcode 这段文字以代码的形式在HTML 中出现时,将自动输出(echo)文字” shortcode教学” 以及档案位置为' http://demo7.../hao-favicon.png">'; } add_shortcode('dh_first_shortcode','dh_first_shortcode'); 加入方式为选择子主题模板,在funtions.php

1.2K30

常用短代码插件:WPJAM Basic 的短代码扩展

WPJAM Basic 常用短代码扩展内置了一些可能经常使用到的「短代码」(Shortcode),让你在编辑文章的时候插入复杂格式的内容更加方便,目前支持的短代码(Shortcode)有这些: email...在 WordPress 后台代码模式下输入表格,总有一种想死的感觉,要输入 等一堆代码,看着头都晕,实在是受不了了,所以就写了 table 这个 Shortcode...RMB 一个月 整站所有页面 侧边栏广告位 300X150 静态图片 500 RMB 一个月 整站所有页面,最多三个 youku, qqv等 为了方便插入视频,提供了B站,腾讯视频,优酷和土豆的 shortcode.../id_XXXXXXXXXXX.html[/youku] 后台短代码列表 另外还在后台列罗出所有的短代码: 本文二次修改自:https://blog.wpjam.com/m/wpjam-basic-shortcode

1.3K30

WordPress 技巧:防止博客内容中的 Email 地址被收集

WordPress 默认有 antispambot 函数,它可以将 email 地址转换成机器无法识别而浏览器能够正确显示的邮件地址,所以我们可以在主题的 functions.php 文件中添加如下的代码: add_shortcode...( 'email', 'wpjam_email_shortcode_handler' ); function wpjam_email_shortcode_handler( $atts, $content...='' ) { extract( shortcode_atts( array( 'mailto' => '0' ), $atts ) ); return antispambot...( $content, $mailto ); } Antispambot ShortCode 使用 Antispambot ShortCode 这个插件使用非常简单,上传激活之后,如果只是简单展示邮件地址...link="1"]you-email-address@email.com[/email] 显示结果为:you-email-address@email.com 自动隐藏邮件地址 当然,如果你不想使用 shortcode

28420
领券