简短代码的简单示例:
function s_print( $atts ){
return 'http://abc.com/?foo=1&bar=2';
}
add_shortcode( 'my_shortcode', 's_print' );
Run Code Online (Sandbox Code Playgroud)
它返回:
http://abc.com/?foo=1&bar=2
Run Code Online (Sandbox Code Playgroud)
此函数通过短代码插入到页面正文的链接[my_shortcode],但&总是更改为&,这会破坏链接(它不再起作用).我google了很多.有一些解决方案:
wp_specialchars_decode($foo);
remove_filter('the_content','wptexturize');
Run Code Online (Sandbox Code Playgroud)
但这些似乎仅用于主题(functions.php),它不适用于短代码(我尝试在短代码函数之前或之内添加它).
我不想落到最后的解决方案,这是在WordPress formatting.php文件中评论一些行,因为我正在开发一个将被许多人使用的插件.
我目前正在编码WordPress短代码,并且涉及一些jquery。为了使jquery正常工作,我需要使用具有唯一#ID的div。如果使用一次简码,则可以正常工作,但是如果他们在页面上多次使用简码,则会破坏javascript。
因此,我想知道每次调用短码时是否有某种方法可以使用唯一的ID?或以某种方式使用不同的ID(如果在页面上多次使用简码)?
假设我有简码功能
function my_shortcode() {
$my_shortcode='<div id="demo">My content</div>';
return $my_shortcode;
} //end function
Run Code Online (Sandbox Code Playgroud)
和jQuery
$("#demo").click(function{
autoplay: true,
});
Run Code Online (Sandbox Code Playgroud) 这听起来应该很简单,或者应该有一个简单的短代码插件来实现这一点,但我已经搜索并搜索了几乎一个小时,但找不到答案。我想要做的就是在正文中显示帖子的发布日期。示例:[meta = "Date"]。是否有一个简单的轻量级解决方案来实现这一目标。我只需要在内容中发布发布日期。谢谢。
我想在wppb插件样板中添加简码,这是样板生成器的链接http://wppb.me, 请告诉它它将如何工作?对你的帮助表示感谢。
在Woocommerce中,我想在WordPress网站的一个简单页面(而非产品页面)上共同创建“添加到购物车”链接。
因此,我尝试了以下代码(此处的产品ID为123):
<a href="http://example.com/cart/?add-to-cart=123">Buy</a>
Run Code Online (Sandbox Code Playgroud)
我已启用AJAX添加到购物车的存档页面Woocommerce选项设置。
但是它不起作用,并且我的自定义购物车链接上未启用Ajax功能。
如何在自定义链接(除woocommerce之外的其他页面)上启用ajax添加到购物车?
我打开了 Gutenberg 并试图在页面上创建一个短代码。这是我在functions.php中的代码
// Enable shortcodes in text areas
add_filter( 'widget_text', 'shortcode_unautop');
add_filter( 'widget_text', 'do_shortcode');
// Enable shortcodes
add_filter( 'the_excerpt', 'shortcode_unautop');
add_filter( 'the_excerpt', 'do_shortcode');
function first_shortcode() {
$content = '<h1>This is my first shortcode</h1>';
return $content;
}
add_action('my_shortcode','first_shortcode');Run Code Online (Sandbox Code Playgroud)
在帖子中,我将 [my_shortcode] 放在了短代码部分,如下所示:
但是当我显示页面时,它只是呈现 [my_shortcode]。我正在运行 Wordpress 4.9.8
谢谢
如何在Windows 10中轻松拍摄我的屏幕.我希望有选择选择我的屏幕的一部分来截取屏幕截图.
嗨所以我在http://scribu.net/wordpress/optimal-script-loading.html上使用了一个很棒的教程,当我在这里使用名为lightbox的短代码是我的代码时,我无法加载脚本.我在调用页面时想要与某人核实是否正确写入.
add_shortcode('lightbox', 'lightbox_handler');
function lightbox_handler($atts) {
$base = get_stylesheet_directory_uri();
wp_enqueue_script('jquery-mousewheel', $base . '/js/jquery.mousewheel-3.0.6.pack.js', array('jquery'), null, true);
wp_enqueue_script('jquery-fancybox', $base . '/js/jquery.fancybox.pack.js', array('jquery'), '1.0', true);
wp_enqueue_script('jquery-fancybox-buttons', $base . '/js/jquery.fancybox-buttons.js', array('jquery-fancybox'), '1.0', true);
wp_enqueue_script('jquery-fancybox-media', $base . '/js/jquery.fancybox-media.js', array('jquery-fancybox'), '1.0', true);
wp_enqueue_script('jquery-fancybox-thumbs', $base . '/js/jquery.fancybox-thumbs.js', array('jquery-fancybox'), '1.0', true);
wp_enqueue_style('jquery-fancybox', $base . '/css/jquery.fancybox.css', false, '1.0', true);
wp_enqueue_style('jquery-fancybox-buttons', $base . '/css/jquery.fancybox-buttons.css', array('jquery-fancybox'), '1.0', true);
wp_enqueue_style('jquery-fancybox-thumbs', $base . '/css/jquery.fancybox-thumbs.css', array('jquery-fancybox'), '1.0', true);
}
function lightbox( $atts, $content = null ) {
$defaults = apply_filters( 'toggle_shortcode_args', …Run Code Online (Sandbox Code Playgroud) 我遇到了一个包含这种代码的应用程序,我不明白什么是{{phrase.addAdministrator}},它来自哪里?
<section class="content" ng-show="views.list"><a ng-click="changeView('add')" class="floatRTL btn btn-success btn-flat pull-right marginBottom15">{{phrase.addAdministrator}}</a>
<div class="box col-xs-12">
<div class="box-header">
<h3 class="box-title">{{phrase.listAdministrators}}</h3>
<div class="box-tools">
<div class="input-group">
<input type="text" name="table_search" ng-model="searchText" class="form-control input-sm pull-right" style="width: 150px;" placeholder="{{phrase.Search}}">
<div class="input-group-btn">
<button class="btn btn-sm btn-default"><i class="fa fa-search"></i></button>
</div>
</div>
</div>
</div>
<div class="box-body table-responsive">
<table class="table table-hover">
<tbody><tr>
<th>{{phrase.ID}}</th>
<th>{{phrase.name}}</th>
<th>{{phrase.username}}</th>
<th>{{phrase.email}}</th>
<th>{{phrase.Operations}}</th>
</tr>
<tr ng-repeat="admin in admins | filter:searchText">
<td>{{admin.id}}</td>
<td>{{admin.fullName}}</td>
<td>{{admin.username}}</td>
<td>{{admin.email}}</td>
<td>
<a ng-click="edit(admin.id)" type="button" class="btn btn-info btn-flat" title="{{phrase.Edit}}" tooltip><i class="fa fa-pencil"></i></a> …Run Code Online (Sandbox Code Playgroud) shortcode ×9
wordpress ×7
php ×3
javascript ×2
ajax ×1
date ×1
function ×1
metadata ×1
screen ×1
screenshot ×1
windows-10 ×1
woocommerce ×1