php - Wordpress 中的短代码和 Ajax 问题
问题描述
我正在尝试在 WordPress 中使用短代码,但它们在 ajax 调用后不起作用(例如,当我单击站点的另一个页面时,ajax 会获取另一个文件file.php
并用它替换登录页面的中心部分)。问题是当页面加载时,短代码在插入代码时会被打印出来。例如,我[instafeed]
应该显示我的 Instagram 提要,但唯一打印的是"[instafeed]"
. 短代码也会发生这种情况[bloginfo key='template_url']
(我从 css-tricks 获取代码)。
我已经尝试了此处显示的一些解决方案,但它们不起作用。例如,我使用了“bloginfo”的代码,它采用了主题文件夹的路径
//StackOverflow solution from https://stackoverflow.com/questions/26069355/call-wordpress-shortcode-with-ajax
add_action( 'init', function() {
ps_register_shortcode_ajax( 'digwp_bloginfo_shortcode',
'digwp_bloginfo_shortcode' );
} );
function ps_register_shortcode_ajax( $callable, $action ) {
if ( empty( $_POST['action'] ) || $_POST['action'] != $action )
return;
call_user_func( $callable );
}
//End of StackOverflow solution
//Code from https://css-tricks.com/snippets/wordpress/bloginfo-shortcode/
function digwp_bloginfo_shortcode( $atts ) {
extract(shortcode_atts(array(
'key' => '',
), $atts));
return get_bloginfo($key);
}
add_shortcode('bloginfo', 'digwp_bloginfo_shortcode');
我希望输出path_of_directory_of_theme/
是
[bloginfo key='template_url']
解决方案
推荐阅读
- ruby-on-rails - 将集合与相关对象分组
- google-chrome - Kentico CMS - 在特定浏览器中打开 URL
- javascript - 如何执行具有顺序求和的循环?
- java - 如何使用 JSON 动态创建 POJO?
- python - 转义单引号和 lxml
- qt - Qt 配置脚本的最小选项
- android - 在 Android 的 Manifest 文件中提供自定义应用程序类时,Flutter 应用程序崩溃
- angular - 如何为从 Angular HTTP 请求接收的数据设置类型?
- reactjs - 当比例大于 x 时更改图像源,使用 React 中的 2 个函数?
- excel - VBA MACRO 仅为一个用户发送空模板