这是我需要在我的网站上工作的短代码(我正在使用来自wp-types.com的工具集)
[wpv-post-body id="3650"]
我需要从我的网址上的值替换3650:new-ticket /?parent_lead_id = 3788
所以我按照这个脚本来复制URL
中的值<script>
function getParam( name )
{
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regexS = "[\\?&]"+name+"=([^&#]*)";
var regex = new RegExp( regexS );
var results = regex.exec( window.location.href );
if( results == null )
return "";
else
return results[1];
}
var frank_param = getParam( 'parent_lead_id' );
document.write(frank_param)
</script>
输出是例如3788
问题是,我不能将这整段代码放在短代码中,因为它不起作用。
由于不支持php:我们不能只输出。我可以使用哪些其他方法?
答案 0 :(得分:0)
我不明白......我刚刚制作了一个短代码,执行Javascript 并使用 PHP来提供 JS以及URL查询var ...
/**
* Usage: [alert]
*/
add_shortcode( 'alert', 'alert_shortcode_so_14229381' );
function alert_shortcode_so_14229381( $atts, $content = null )
{
if( !isset( $_GET['msg'] ) )
return;
$alert = $_GET['msg'];
$html = "<script>alert('{$alert}');</script>";
return $html;
}