1、问题 换新设备后迁移基于hugo构建的静态博客出现的报错,报错如下: failed to extract shortcode: template for shortcode "admonition
WooCommerce配备了很多shortcode短代码(简码),可以直接在post帖子和page页面内插入内容,方便展示产品、分类等。 php echo do_shortcode('[product]'); ? 您还可以使用以下代码按自定义元字段对产品进行排序(在本例中,我们按价格对产品进行排序): add_filter( 'woocommerce_shortcode_products_query', 'woocommerce_shortcode_products_orderby ' ); function woocommerce_shortcode_products_orderby( $args ) { $standard_array = array('menu_order
我们在使用 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 '
Shortcode 类型 Shortcode API 支持几乎所有可能的组合形式:自关闭标签,开放标签,含有参数的标签等。 Shortcode 基本概念 Shortcode 是怎么解析成所需的内容的呢? 这是因为每个 Shortcode 都定义了一个对应的回调函数来处理,这个回调函数一般有两个参数:Shortcode 的属性参数和内容: function my_shortcode_func($attr, add_shortcode('mycode', 'my_shortcode_func'); Shortcode 相关的函数 WordPress 定义了以下和 Shortcode 相关的函数: add_shortcode 比如在侧边栏的 Widgets 中: add_filter('widget_text', 'do_shortcode'); 在主题中,直接调用 do_shortcode 方法: echo do_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
在 WordPress 后台代码模式下输入表格,总有一种想死的感觉,要输入
| 等一堆代码,看着头都晕,实在是受不了了,所以就写了下面这个插件,使用 Shortcode php
/*
Plugin Name: WPJAM Table Shortcode
Plugin URI: http://blog.wpjam.com/m/wordpress-shortcode-for-table /
Description: 使用 Shortcode 快速输入表格。 Version: 0.1
Author: Denis
*/
add_shortcode( 'table', 'wpjam_table_shortcode_handler' );
function wpjam_table_shortcode_handler ( $atts, $content='' ) {
extract( shortcode_atts( array(
'border' => '1', 60140编辑于 2023-04-15 来自专栏WordPress果酱 WordPress 技巧:删除列表页的 Shortcode有时候我们希望保持首页和其他列表页尽可能的简单,比如不输出 Shortcode: /* Plugin Name: 删除列表页的 Shortcode Plugin URI: http://blog.wpjam.com /m/remove-shortcode-from-archive/ Description: 删除首页和其他列表页的 Shortcode。 Version: 0.1 Author: Denis Author URI: http://blog.wpjam.com/ */ function wpjam_remove_shortcode_from_archive content = strip_shortcodes( $content ); } return $content; } add_filter('the_content', 'wpjam_remove_shortcode_from_archive 85510编辑于 2023-04-15 来自专栏WordPress果酱 WordPress 技巧:使用 Shortcode 快速插入列表我们可以使用 WordPress Shortcode 实现快速插入列表: 首先将下面的代码复制到当前主题的 functions 文件中,或者直接保存一个插件,并上传激活: <? php /* Plugin Name: WPJAM List Shortcode Plugin URI: http://blog.wpjam.com/m/wordpress-shortcode-for-list / Description: 使用 Shortcode 快速输入列表。 Version: 0.1 Author: Denis */ add_shortcode( 'list', 'wpjam_list_shortcode_handler' ); function wpjam_list_shortcode_handler ( $atts, $content='' ) { extract( shortcode_atts( array( 'type' => '0' ), $atts ) ); 48210编辑于 2023-04-15 来自专栏WordPress果酱 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' = 84310编辑于 2023-04-15 来自专栏WordPress果酱 WordPress 技巧:使用 Shortcode 方式插入视频,并支持全平台播放而优酷和土豆本身已经提供了支持全平台的嵌入代码,我就写了一个 Shortcode 让你非常方便的在文章中插入优酷视频,并支持全平台播放: <? php /* Plugin Name: 使用 shortcode 方式插入优酷和土豆视频,并支持全平台播放 Plugin URI: http://blog.wpjam.com/m/video-shortcode / Author: Denis */ add_shortcode( 'youku', 'wpjam_youku_shortcode' ); function wpjam_youku_shortcode ( 'tudou', 'wpjam_tudou_shortcode' ); function wpjam_tudou_shortcode( $atts, $content='' ) { extract ( shortcode_atts( array( 'width' => '480', 'height' => '400', ), $atts ) ) 74420编辑于 2023-04-15 来自专栏WordPress果酱 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( 37220编辑于 2023-04-15 来自专栏owent AI真好用-给Blog主题统一加mermaid,chart.js,excalidraw,draw.io的多种引入方式支持[](file.ext) Code block: ```language Shortcode with src: {{< type src="file" >}} Shortcode inline: {{ 引用外部文件 1.4 Shortcode 内联方式 <mxfile host="app.diagrams.net"> <diagram name="Page-1" id="<em>shortcode</em>-inline-test B -->|是| C[蓝色流程图] B -->|否| D[检查代码] 2.3 <em>Shortcode</em> 引用外部文件 Loading mermaid diagram... 2.4 <em>Shortcode</em> 内联方式 graph TD A[<em>Shortcode</em> 内联] --> B[Mermaid 图表] B --> C{正常显示?} 测试结果 类型 图片语法 代码块方式 <em>Shortcode</em> (内联) <em>Shortcode</em> (src) Draw.io/diagrams.net ✓ .drawio ✓ drawio ✓ ✓ Mermaid 13810编辑于 2026-03-27 来自专栏DeveWork 丰富排版页面——为你的wordpress主题添加短代码形式美化框.= ' 2.6K60发布于 2018-01-19 来自专栏WordPress果酱 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 49620编辑于 2023-04-15 来自专栏建站技术博客 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.8K30编辑于 2022-04-11 在springboot中缩短一个url链接= shortCode; this.createdAt = createdAt; this.expiresAt = expiresAt; this.visitCount ); } @GetMapping("/{shortCode}") public ResponseEntity<? (shortCode); return urlOptional .map(url -> ResponseEntity.status(302).header(" }/stats") public ResponseEntity<Integer> getUrlStats(@PathVariable String shortCode) { int 使用 GET 请求 /api/url/{shortCode} 重定向到原始 URL。使用 GET 请求 /api/url/{shortCode}/stats 获取短 URL 的访问量。 1.4K10编辑于 2024-12-19 来自专栏苏三说技术 100万QPS短链系统如何设计?bloomFilter.mightContain(shortCode)) { returnnull; } // 2. 获取分布式锁 String lockKey = "lock:" + shortCode; if (redis.setnx(lockKey, "1", )) { // 10秒超时 查数据库 longUrl = db.queryLongUrl(shortCode); if (longUrl ! 等待重试 Thread.sleep(); return getLongUrl(shortCode); } } 防护要点: 布隆过滤器拦截非法短码 分布式锁防止缓存击穿 shortCode) { // 取短码的CRC32值 CRC32 crc32 = new CRC32(); crc32.update(shortCode.getBytes()) 39100编辑于 2025-06-23 来自专栏主机教程网 2bcd.com 的专栏 如何用短代码实现内容WordPress会员登录可见?1、将下面的代码添加到主题functions.php模板文件中: function member_check_shortcode($atts, $content = null) { if (is_user_logged_in is_feed()) { return do_shortcode($content); } return ' 请注册登录后查看内容 ';} add_shortcode('member', 'member_check_shortcode'); 2、然后在编辑文章是可以通过添加短代码,只有登录用户才能看到的内容 [member]登录后显示的内容96040编辑于 2022-11-28 来自专栏WordPress技术文章 wordpress调用指定ID页面内的相册$page) return ''; // 提取相册短代码 $pattern = get_shortcode_regex(array('gallery')); if (preg_match ("/$pattern/", $page->post_content, $matches)) { return do_shortcode($matches[0]); } return '';}add_shortcode('page_gallery', 'display_page_gallery');然后,在首页模板(通常是front-page.php或home.php) php echo do_shortcode('[page_gallery page_id="2"]'); ?>方法二:直接修改首页模板如果你熟悉主题开发,可以直接在首页模板中添加:<? (array('gallery')); if (preg_match("/$pattern/", $content, $matches)) { echo do_shortcode($ 23410编辑于 2025-06-24 来自专栏主机教程网 2bcd.com 的专栏 WordPress 怎么利用短代码实现移动设备上内容不可见?function not_mobile_shortcode($atts, $content = '') { if (wp_is_mobile() === true) { $content = ''; } return $content;} add_shortcode('not_mobile', 'not_mobile_shortcode'); 2、将代码添加到主题functions.php 1.2K40编辑于 2022-11-04 |