我在WordPress插件开发新手,在这件事情我都有种打了一个路障。问题是,使用过滤器add_filter('robots_txt', 'AddToRobotsTxt', 10, 2);
不会产生在我的本地我不知道是什么问题robots.txt文件。我已设置目录权限
<Directory />
AllowOverride All
Require all granted
</Directory>
因为我认为这可能会导致问题,我安装我的代码的其余部分。
public function allRobotSettings(){
register_setting('energizer_robot_group', 'energizer_robots-name');
add_settings_section('energizer_robot_index', 'Robot Setting', array( $this->callbacks_mngr, 'robotSectionManager' )
, 'energizer_robots');
add_settings_field('robot_field_manager', 'Robot Document', array( $this->callbacks_mngr, 'robotInputboxField' ),
'energizer_robots', 'energizer_robot_index');
}
此功能对于HTML页面上设置。并调用这些功能。
public function robotSectionManager()
{
echo 'Edit your robot.txt file here.';
}
public function robotInputboxField()
{
$data=get_option('energizer_robots-name');
add_filter( 'robots_txt', 'AddToRobotsTxt',10,2);
$content=get_option('energizer_robots-name');
echo '<div ><input type="text" name="energizer_robots-name" value="'. $content.'"
style="height: 150px;
width: 100%;
box-sizing: border-box;
border: 2px solid #ccc;
border-radius: 4px;
background-color: #f8f8f8; ></div>';
}
public function AddToRobotsTxt($robotstext, $public) {
$robotsrules = get_option('energizer_robots-name');
$new_value=$robotstext . $robotsrules;
update_option( 'energizer_robots-name', $new_value);
return $robotstext . $robotsrules;
}
任何帮助,将不胜感激。
刚刚尝试在你的插件的基础文件中添加这一点,它可以移动到类初始化上采取行动。还请创建一个robots.txt文件,如果没有。
add_filter( 'robots_txt', 'AddToRobotsTxt',10,2);
function AddToRobotsTxt($robotstext, $public) {
$robotsrules = get_option('energizer_robots-name');
$new_value=$robotstext . $robotsrules;
update_option( 'energizer_robots-name', $new_value);
return $robotstext . $robotsrules;
}