详解WordPress中简码格式标签编写的基本方法
把简码执行成需要的内容, , $func ); 例如添加名为 test 的简码,对文章内容是一种很好的扩展。
Bing_shortcode_test ); 只有页面中使用了简码的时候才加载脚本 而在开发的过程中, 1 2 3 4 5 6 7 8 9 10 11 12 13 //添加简码 function Bing_add_google_map( $atts,回调 Bing_shortcode_test() 函数: 1 2 3 4 function Bing_shortcode_test( $attr, 1 remove_shortcode( test ); remove_all_shortcodes() 函数用来移除当前添加的所有简码,两个属性,只需要指定简码的名称即可移除, test ) ) echo 字符串中有 test 简码;//False $content = 测试测试测试测[test]测试[/test]试测试测试测试测试; if( has_shortcode( $content,可以是有属性、无属性、闭合、非闭合等等: [example] [example]内容[/example] [example attr=属性 attr-hide=1]内容[/example] [example 属性] 添加简码 添加简码需要使用 add_shortcode() 函数, Bing_add_google_map); //挂载脚本 function Bing_add_javascript(){ global $google_map_shortcode; if( isset( $google_map_shortcode ) $google_map_shortcode ) wp_enqueue_script( map_scripts ); } add_action( wp_footer,第一个是简码所有的属性, 1 add_shortcode( $tag, 简码格式 简码的格式非常灵活, 从上边的例子可以看到,这怎么做到呢? 其实很简单,而当页面没有使用简码的时候就会造成资源浪费,利用好可以让添加某些东西变的方便快捷。
shortcode_exists() 函数判断简码是否存在,会在本文全部介绍。
Bing_shortcode_test ); if( shortcode_exists( test ) ) echo 简码 test 存在;//True 还有一个 has_shortcode() 函数, text = 点击隐藏 / 显示 ),简码的回调函数需要接收两个参数, test ) ) echo 字符串中有 test 简码;//True 执行简码 do_shortcode() 函数用来在字符串中查找简码,可以使用 shortcode_atts() 函数: 1 2 3 4 5 6 7 8 9 10 function Bing_shortcode_test( $attr, 移除简码 remove_shortcode() 函数可以移除一个简码, $attr ) ); $hide = $hide ? style=display:none; : ; return a href= . $url . . $hide . . $text . /a; } add_shortcode( test,第二个是简码的回调函数,简码很多人叫做短代码,格式类似于把尖括号换成中括号的 Html 标签,有两个函数,通过数组储存;第二个是简码的内容(闭合简码中的内容), $content ){ return Hello World!; } add_shortcode( test,在这里纠正一下。
Bing_add_google_map); //挂载脚本 function Bing_add_javascript(){ wp_enqueue_script( map_scripts ); } add_action( wp_enqueue_scripts, 简码的开发的逻辑比较简单,第一个为简码名, Bing_shortcode_test ); 在文章中添加 [test] 就会输出 Hello World!, $content ){ //content... } add_shortcode( google_map, $content ){ extract( shortcode_atts( array( url = 。
只需要在简码函数触发的时候在页脚挂载脚本即可, $content ){ $GLOBALS[google_map_shortcode] = true; return 地图的代码; } add_shortcode( google_map,接受给简码回调函数的第一个参数, do_shortcode,判断字符串中是否出现某某简码,但官方的翻译应该是简码,有时会遇到这种问题:简码模块需要加载 JS 或者 CSS 脚本, 比如下边的这个 Google 地图插件: 1 2 3 4 5 6 7 8 9 10 11 //添加简码 function Bing_add_google_map( $atts, $content ){ return Hello World!; } add_shortcode( test, 1 remove_all_shortcodes(); 判断简码 关于判断简码, 1 2 3 4 $content = 测试测试测试测试测试测试测试测试; if( has_shortcode( $content, Bing_shortcode_test ); $content = 测试测试测试测[test]试测试测试测试测试; echo do_shortcode( $content );//测试测试测试测Hello World!试测试测试测试测试 简码属性 简码支持各种格式的属性, Bing_add_javascript ); 总结 简码是个非常强大的功能, Bing_add_javascript ); 只有在页面中使用了 [google_map] 简码的时候才需要加载脚本, 11 ); 例子: 1 2 3 4 5 6 function Bing_shortcode_test( $attr, WordPress 简码是一种类似于论坛标签的东西,如果你要给参数设置默认值,主要就是添加、删除和判断。
WordPress 添加的钩子: 1 add_filter( the_content, 1 2 3 4 remove_all_shortcodes(); if( shortcode_exists( test ) ) echo 简码 test 存在;//False add_shortcode( test,并在简码处调用之前添加的回调函数, hide = false,。
相关热词:
本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供用于网络技术学习参考,学习中请遵循相关法律法规!
本文地址: https://v30.fanwenzhu.com/jz/wp/11081.shtml
相关文章
热门TAG
win10 ecshop 主机 阿里云 解决 配置 C# C++ 解析 SQL语句 命令 Go语言 方法 CSS3 HTML5 CSS win7 MSSQL 服务器配置 IIS7.5 IIS7 IIS6 IIS CentOS 7 Linux oracle数据库 oracle phpcms discuz discuz教程最新文章
-
ludou_se_only); } add_action(s
时间:2021-01-23
-
所以经常导致输错密码的
时间:2021-01-23
-
WordPress措施打开速度慢的
时间:2021-01-22
-
WordPress回覆评论自动添加
时间:2021-01-22
-
我们可以通过下面的代码
时间:2021-01-22
-
如何修改WordPress默认脚色
时间:2021-01-20
-
同样的修改文件就行
时间:2021-01-20
-
少数善意的转载者既使没
时间:2021-01-20
热门文章
-
WordPress新手安装教程(图文)
时间:2020-12-28
-
在设置菜单中增加WordPress私密 隐藏的全部
时间:2021-01-10
-
WordPress博客程序常见错误的解决方法
时间:2020-12-28
-
WordPress程序打开速度慢的三种解决方法
时间:2021-01-10
-
wordpress使用代码在每篇文章尾部添加版权
时间:2020-12-14
-
WordPress博客措施常见错误的办理要领
时间:2021-01-15
-
关于WordPress的SEO优化相关的一些PHP页面脚
时间:2021-01-07
-
WordPress措施打开速度慢的三种办理要领
时间:2021-01-22
-
详解WordPress中的头像缓存和署理中的缓存
时间:2021-01-15
-
少数善意的转载者既使没有看到版权信息
时间:2021-01-20
