如果您使用的是PHP>5.3,那么可以在the_content 滤器需要在$variable 已定义且在the_content 筛选器已启动。
add_filter( \'the_content\', function( $content ) use ( $variable ) {
return str_replace( \'[variable][/variable]\', $variable, $content );
} );
短代码是在
the_content 以11的优先级挂起。因此,任何优先级为10或更低的都将在此之前运行。如果希望在之前运行回调
wpautop, 使用小于10的优先级。
没有理由add_shortcode() 因为这段代码用之前的变量替换了shortcodedo_shortcode() 正在运行。
过滤器最好放置在主题函数中。php文件,但如果出于某种原因$variable 函数不可用。php,那么这个小技巧应该可以奏效。