所以我在我的my_example_shortcode站点上有了WordPress的短代码。
add_shortcode( 'my_example_shortcode', 'shortcode_for_project' );
我想在add_filter('the_content', 'my_example');之前对短代码进行优先级排序
如果在页面上找不到短代码,那么我希望上面的代码被应用。
我已经试过了:
if (shortcode_for_project) {
echo do_shortcode('[my_example_shortcode]');
}
else
{
add_filter('the_content', 'my_example');
}假设我有一页:
商务智能
Lorem ipsum dolor坐好了,敬请光临。大菱鲆,大菱鲆,小茴香。
那么我希望add_filter('the_content', 'my_example');是启用的
但是如果
商务智能
my_example_shortcode
Lorem ipsum dolor坐好了,敬请光临。大菱鲆,大菱鲆,小茴香。
那么我希望add_filter('the_content', 'my_example');成为禁用的
发布于 2022-04-27 16:25:12
如果我理解这里的问题,你可以这样做:
// functions.php
add_filter("the_content", function($content) {
if (shortcode_exists('my_example_shortcode')) {
ob_start();
echo do_shortcode('[my_example_shortcode]');
return ob_get_clean();
}
return my_example($content);
});https://stackoverflow.com/questions/72029411
复制相似问题