Javascript 仅从一个页面中删除statcounter脚本
我正试图从wordpress站点的一个页面中删除statcounter脚本(我在页脚中有),这样它就不会计算该页面了,特别是因为它的隐藏元素 我研究过php插件,但它没有注册或排队任何脚本,所以我不知道使用什么函数。下面是其php的一个片段:Javascript 仅从一个页面中删除statcounter脚本,javascript,Javascript,我正试图从wordpress站点的一个页面中删除statcounter脚本(我在页脚中有),这样它就不会计算该页面了,特别是因为它的隐藏元素 我研究过php插件,但它没有注册或排队任何脚本,所以我不知道使用什么函数。下面是其php的一个片段: $sc_position = get_option(key_sc_position); if ($sc_position=="header") { add_action('wp_head', 'add_statcounter'); } else {
$sc_position = get_option(key_sc_position);
if ($sc_position=="header") {
add_action('wp_head', 'add_statcounter');
} else {
add_action('wp_footer', 'add_statcounter');
}
// The guts of the StatCounter script
function add_statcounter() {
global $user_level;
$sc_project = get_option(key_sc_project);
$sc_security = get_option(key_sc_security);
$sc_invisible = 0;
$sc_invisible = get_option('sc_invisible');
if (
( $sc_project > 0 )
) {
?>
<!-- Start of StatCounter Code -->
<script>
<!--
var sc_project=<?php echo $sc_project; ?>;
var sc_security="<?php echo $sc_security; ?>";
<?php
if($sc_invisible==1) {
echo " var sc_invisible=1;\n";
}
define('HTTPS', isset($_SERVER['HTTPS']) && filter_var($_SERVER['HTTPS'], FILTER_VALIDATE_BOOLEAN));
$protocol = defined('HTTPS') ? "https:" : "http:";
?>
var scJsHost = (("https:" == document.location.protocol) ?
"https://secure." : "http://www.");
//-->
document.write("<sc"+"ript src='" +scJsHost +"statcounter.com/counter/counter.js'></"+"script>");
</script>
<!-- End of StatCounter Code -->
<?php
}
}
但它不起作用,任何人都知道我如何完成它?所以你看到了:
$sc_position = get_option(key_sc_position);
if ($sc_position=="header") {
add_action('wp_head', 'add_statcounter');
} else {
add_action('wp_footer', 'add_statcounter');
}
如果是某个页面,我们不想这样做
为了获得特定页面,请查看此
也就是说,如果我当前的页面名不等于我要忽略的页面,那么添加计数器。。。并且尽可能地去掉你所做的代码
add_action( 'wp_footer', 'no_stat_counter_scripts' );
add_action( 'wp_head', 'no_stat_counter_scripts');
试试看:
<?php
function add_statcounter() {
if(is_page('id or slug of page to exclude')) return;
global $user_level;
$sc_project = get_option(key_sc_project);
$sc_security = get_option(key_sc_security);
$sc_invisible = 0;
$sc_invisible = get_option('sc_invisible');
if ( ( $sc_project > 0 )) {
?>
<!-- Start of StatCounter Code -->
<script>
<!--
var sc_project=<?php echo $sc_project; ?>;
var sc_security="<?php echo $sc_security; ?>";
<?php
if($sc_invisible==1) {
echo "var sc_invisible=1;\n";
}
define('HTTPS', isset($_SERVER['HTTPS']) && filter_var($_SERVER['HTTPS'], FILTER_VALIDATE_BOOLEAN));
$protocol = defined('HTTPS') ? "https:" : "http:";
?>
var scJsHost = (("https:" == document.location.protocol) ?
"https://secure." : "http://www.");
//-->
document.write("<sc"+"ript src='" +scJsHost +"statcounter.com/counter/counter.js'></"+"script>");
</script>
<!-- End of StatCounter Code -->
<?php
}
}
文件。填写(“”);
add_action( 'wp_footer', 'no_stat_counter_scripts' );
add_action( 'wp_head', 'no_stat_counter_scripts');
<?php
function add_statcounter() {
if(is_page('id or slug of page to exclude')) return;
global $user_level;
$sc_project = get_option(key_sc_project);
$sc_security = get_option(key_sc_security);
$sc_invisible = 0;
$sc_invisible = get_option('sc_invisible');
if ( ( $sc_project > 0 )) {
?>
<!-- Start of StatCounter Code -->
<script>
<!--
var sc_project=<?php echo $sc_project; ?>;
var sc_security="<?php echo $sc_security; ?>";
<?php
if($sc_invisible==1) {
echo "var sc_invisible=1;\n";
}
define('HTTPS', isset($_SERVER['HTTPS']) && filter_var($_SERVER['HTTPS'], FILTER_VALIDATE_BOOLEAN));
$protocol = defined('HTTPS') ? "https:" : "http:";
?>
var scJsHost = (("https:" == document.location.protocol) ?
"https://secure." : "http://www.");
//-->
document.write("<sc"+"ript src='" +scJsHost +"statcounter.com/counter/counter.js'></"+"script>");
</script>
<!-- End of StatCounter Code -->
<?php
}
}