最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

callbacks - JavaScript missing from shortcode content

programmeradmin0浏览0评论

I am trying to add a short javascript as part of registering a WP shortcode. You can see my simplified code below. When I execute this on my website everything loads fine except for the part between the <script> ... </script> tags. I looked at the source code after the page has loaded and neither the <script> tags nor the function in between is there.

I don't know what I'm doing wrong.

Is there a filter in WP that removes <script> tags?

Thank you!

// register custom shortcodes
function psb_register_shortcodes() {
    add_shortcode('psb-booking', 'psb_booking_shortcode');
}

function psb_booking_shortcode( $args, $content='' ) {
    global $wpdb; 
    $output = 
        '<script>
             function doSomething () {};
         </script>';
    $output .= '<p> testing </p>';
    
    $table_name = $wpdb->prefix . 'psb_booking';
    foreach ( $wpdb->get_col( $wpdb->prepare("DESC " . $table_name, 0 )) as $column_name ) {
        error_log( $column_name );
    }
    
    $output .= file_get_contents(plugin_dir_path( __FILE__ ) . 'includes/psb-booking.html');

    return $output;
}
发布评论

评论列表(0)

  1. 暂无评论