dongmin1166 2017-08-16 13:14
浏览 41

Wordpress自定义短代码 - >如果没有参数则不显示

A simple wordpress shortcode function gets the querystring key => value pair from the URL and outputs the value onto the page where the shortcode is placed. I set the parameter in the shortcode to determine which key to call e.g. [urlparam param="username"].

Unfortunately, if there is no querystring or if the querystring key is not present then the raw shortcode displays on the page rather than rendering any result or displaying nothing. How would I edit the shortcode function so that nothing displays if there is no querystring or if the key being looked for is not there?

function urlparam_function( $atts ) {  
    extract( shortcode_atts( array(
        'param' => 'param',
    ), $atts ) );
    return $_GET[$param];
}
add_shortcode('urlparam', 'urlparam_function');
  • 写回答

2条回答 默认 最新

  • douba8819 2017-08-16 13:19
    关注

    remove $_GET use only $param like below:

    function urlparam_function( $atts ) {  
        extract( shortcode_atts( array(
            'param' => 'param',
        ), $atts ) );
        return $param;
    }
    add_shortcode('urlparam', 'urlparam_function');
    
    评论

报告相同问题?

悬赏问题

  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图