WordPress add_filter is not working for robots_txt in localhost

Solution:

Just try adding this in your plugin base file, it can be moved to class on init action. Also please create one robots.txt file if there is not.

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;
}