Skip to main content
Fixed grammar and removed link to StackOverflow question which no longer exists.
Source Link

Wordpress add_filter doesn't work

I asked my question in stackoverflow but I should ask it here too (it belongs to the both sites or I'm misunderstanding!)

I'm developing a plugin to replace a character for some user agents in titles, posts and comments but the filter doesn't work. hereHere is the plugin:

<?php
/*
Plugin Name: WP-HalfSpace
Description: نمایش فاصله به‌جای نیم‌فاصله برای گوگل برای خراب‌نشدن نوشته در نتایج جست‌وجوی گوگل
Version: 1.0.0
Author: ahmadalli
Author URI: http://2barnamenevis.com
*/
function HalfSpace_filter($content)
{
    
    $u_agent = $_SERVER['HTTP_USER_AGENT'];
    echo "hi";
    if(($u_agent=="Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)" )
    || ($u_agent=="Googlebot/2.1 (+http://www.googlebot.com/bot.html)")
    || ($u_agent=="Googlebot/2.1 (+http://www.google.com/bot.html)")
    || ($u_agent=="Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)")
    )
    { 
        echo "aaaaaaaaa";
        $content=str_ireplace("‌‌"," ",$content); //"" is not empty. it's a persian character names halfspace.
    }
    return $content;
}

register_activation_hook( __FILE__, 'HalfSpacePlugin_activate' );

function HalfSpacePlugin_activate()
{
    add_filter('the_title','HalfSpace_filter',1,1);
    add_filter('the_content','HalfSpace_filter',1,1);
    add_filter('comment_text','HalfSpace_filter',1,1);
}



register_deactivation_hook( __FILE__, 'HalfSpacePlugin_deactivate' );

function HalfSpacePlugin_deactivate()
{
    remove_filter('the_title','HalfSpace_filter');
    remove_filter('the_content','HalfSpace_filter');
    remove_filter('comment_text','HalfSpace_filter');
}
?>

but theThe filter doesn't work at all because echo "hi"; in HalfSpace_filter doesn't do it's job!

Can anybody help me?

Wordpress add_filter doesn't work

I asked my question in stackoverflow but I should ask it here too (it belongs to the both sites or I'm misunderstanding!)

I'm developing a plugin to replace a character for some user agents in titles, posts and comments but the filter doesn't work. here is the plugin:

<?php
/*
Plugin Name: WP-HalfSpace
Description: نمایش فاصله به‌جای نیم‌فاصله برای گوگل برای خراب‌نشدن نوشته در نتایج جست‌وجوی گوگل
Version: 1.0.0
Author: ahmadalli
Author URI: http://2barnamenevis.com
*/
function HalfSpace_filter($content)
{
    
    $u_agent = $_SERVER['HTTP_USER_AGENT'];
    echo "hi";
    if(($u_agent=="Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)" )
    || ($u_agent=="Googlebot/2.1 (+http://www.googlebot.com/bot.html)")
    || ($u_agent=="Googlebot/2.1 (+http://www.google.com/bot.html)")
    || ($u_agent=="Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)")
    )
    { 
        echo "aaaaaaaaa";
        $content=str_ireplace("‌‌"," ",$content); //"" is not empty. it's a persian character names halfspace.
    }
    return $content;
}

register_activation_hook( __FILE__, 'HalfSpacePlugin_activate' );

function HalfSpacePlugin_activate()
{
    add_filter('the_title','HalfSpace_filter',1,1);
    add_filter('the_content','HalfSpace_filter',1,1);
    add_filter('comment_text','HalfSpace_filter',1,1);
}



register_deactivation_hook( __FILE__, 'HalfSpacePlugin_deactivate' );

function HalfSpacePlugin_deactivate()
{
    remove_filter('the_title','HalfSpace_filter');
    remove_filter('the_content','HalfSpace_filter');
    remove_filter('comment_text','HalfSpace_filter');
}
?>

but the filter doesn't work at all because echo "hi"; in HalfSpace_filter doesn't do it's job!

Can anybody help me?

add_filter doesn't work

I'm developing a plugin to replace a character for some user agents in titles, posts and comments but the filter doesn't work. Here is the plugin:

<?php
/*
Plugin Name: WP-HalfSpace
Description: نمایش فاصله به‌جای نیم‌فاصله برای گوگل برای خراب‌نشدن نوشته در نتایج جست‌وجوی گوگل
Version: 1.0.0
Author: ahmadalli
Author URI: http://2barnamenevis.com
*/
function HalfSpace_filter($content)
{
    
    $u_agent = $_SERVER['HTTP_USER_AGENT'];
    echo "hi";
    if(($u_agent=="Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)" )
    || ($u_agent=="Googlebot/2.1 (+http://www.googlebot.com/bot.html)")
    || ($u_agent=="Googlebot/2.1 (+http://www.google.com/bot.html)")
    || ($u_agent=="Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)")
    )
    { 
        echo "aaaaaaaaa";
        $content=str_ireplace("‌‌"," ",$content); //"" is not empty. it's a persian character names halfspace.
    }
    return $content;
}

register_activation_hook( __FILE__, 'HalfSpacePlugin_activate' );

function HalfSpacePlugin_activate()
{
    add_filter('the_title','HalfSpace_filter',1,1);
    add_filter('the_content','HalfSpace_filter',1,1);
    add_filter('comment_text','HalfSpace_filter',1,1);
}



register_deactivation_hook( __FILE__, 'HalfSpacePlugin_deactivate' );

function HalfSpacePlugin_deactivate()
{
    remove_filter('the_title','HalfSpace_filter');
    remove_filter('the_content','HalfSpace_filter');
    remove_filter('comment_text','HalfSpace_filter');
}
?>

The filter doesn't work at all because echo "hi"; in HalfSpace_filter doesn't do it's job!

Can anybody help me?

Source Link

Wordpress add_filter doesn't work

I asked my question in stackoverflow but I should ask it here too (it belongs to the both sites or I'm misunderstanding!)

I'm developing a plugin to replace a character for some user agents in titles, posts and comments but the filter doesn't work. here is the plugin:

<?php
/*
Plugin Name: WP-HalfSpace
Description: نمایش فاصله به‌جای نیم‌فاصله برای گوگل برای خراب‌نشدن نوشته در نتایج جست‌وجوی گوگل
Version: 1.0.0
Author: ahmadalli
Author URI: http://2barnamenevis.com
*/
function HalfSpace_filter($content)
{
    
    $u_agent = $_SERVER['HTTP_USER_AGENT'];
    echo "hi";
    if(($u_agent=="Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)" )
    || ($u_agent=="Googlebot/2.1 (+http://www.googlebot.com/bot.html)")
    || ($u_agent=="Googlebot/2.1 (+http://www.google.com/bot.html)")
    || ($u_agent=="Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)")
    )
    { 
        echo "aaaaaaaaa";
        $content=str_ireplace("‌‌"," ",$content); //"" is not empty. it's a persian character names halfspace.
    }
    return $content;
}

register_activation_hook( __FILE__, 'HalfSpacePlugin_activate' );

function HalfSpacePlugin_activate()
{
    add_filter('the_title','HalfSpace_filter',1,1);
    add_filter('the_content','HalfSpace_filter',1,1);
    add_filter('comment_text','HalfSpace_filter',1,1);
}



register_deactivation_hook( __FILE__, 'HalfSpacePlugin_deactivate' );

function HalfSpacePlugin_deactivate()
{
    remove_filter('the_title','HalfSpace_filter');
    remove_filter('the_content','HalfSpace_filter');
    remove_filter('comment_text','HalfSpace_filter');
}
?>

but the filter doesn't work at all because echo "hi"; in HalfSpace_filter doesn't do it's job!

Can anybody help me?