下面添加了短代码[my_t_shortcode]
, 它接受一个属性“lang”,并将上述函数应用于内容。
//Add shortcodes
add_shortcode( \'my_t_shortcode\', \'wpse41477_shortcode_handler\' );
//It\'s good practise to make sure your functions are prefixed by something unique
function wpse41477_shortcode_handler( $atts, $content = null ) {
//This will extract \'lang\' attribute as $lang. You can supply default values too.
extract( shortcode_atts( array(
\'lang\' => \'default_lang\',
), $atts ) );
//The above lowercases all values.
/* Apply external function. \'display\' is too generic,
* give it a unique prefix to prevent a clash with another plugin/theme/WordPress
*/
$content = wpse41477_display($content,13);
//why not do $content = mb_substr($content,0,13); instead?
//Apply divs
$content = "<div id=\'translator\' class=\'translate_".$lang."\'>".$content."</div>";
//Not sure what the following is for, but I\'ve left it in.
if($lang == $_SESSION[\'language\']):
return $content;
endif;
}
和自定义功能:
function wpse41477_display($shortcodecontent, $noofchars){
$content2 = mb_substr($shortcodecontent,0,$noofchars);
return $content2;
}
如果这一切
wpse41477_display
是的,我强烈建议您直接将其包含在shortcode处理程序中(请参阅注释)。
以上代码未经测试