/ / वर्डप्रेस फ़ंक्शन robots.txt को अपडेट करने या बनाने के लिए - वर्डप्रेस, फ़ंक्शन, robots.txt

Robots.txt को अद्यतन या बनाने के लिए वर्डप्रेस फ़ंक्शन - वर्डप्रेस, फ़ंक्शन, robots.txt

मैं फ़ाइल robots.txt को अपडेट करने के लिए या अभी तक मौजूद नहीं है तो इसे बनाने के लिए एक फ़ंक्शन के साथ एक प्लगइन बना रहा हूं।

अब तक मेरे पास यह कार्य है:

function roots_robots() {

echo "Disallow: /cgi-binn";
echo "Disallow: /wp-adminn";
echo "Disallow: /wp-includesn";
echo "Disallow: /wp-content/pluginsn";
echo "Disallow: /pluginsn";
echo "Disallow: /wp-content/cachen";
echo "Disallow: /wp-content/themesn";
echo "Disallow: /trackbackn";
echo "Disallow: /feedn";
echo "Disallow: /commentsn";
echo "Disallow: /category/*/*n";
echo "Disallow: */trackbackn";
echo "Disallow: */feedn";
echo "Disallow: */commentsn";
echo "Disallow: /*?*n";
echo "Disallow: /*?n";
echo "Allow: /wp-content/uploadsn";
echo "Allow: /assetsn";
echo "n";
}

add_action("do_robots", "roots_robots");

फ़ाइल robots.txt अपडेट नहीं हो रही है, क्या मैं कुछ भी भूल गया हूं? क्या मौजूदा और फ़ाइल नहीं बनाने पर पहले जाँचने का कोई तरीका है?

मुझे प्लगइन केबी-रोबोट से कुछ मिला लेकिन मुझे "100% यकीन नहीं है कि इसे अपने फ़ंक्शन में कैसे जोड़ा जाए ..

function kb_robotstxt(){
# this is to make it work for demos and testing. Without this, plugin would only act when robots.txt is in a valid place. With this, it will act whenever robots.txt is appended to blog URL
# (even if blog is in a subdirectory)
$request = str_replace( get_bloginfo("url"), "", "http://".$_SERVER["HTTP_HOST"].$_SERVER["REQUEST_URI"] );

if ( (get_bloginfo("url")."/robots.txt" != "http://".$_SERVER["HTTP_HOST"].$_SERVER["REQUEST_URI"]) && ("/robots.txt" != $_SERVER["REQUEST_URI"]) && ("robots.txt" != $_SERVER["REQUEST_URI"]) )
return;     // checking whether they"re requesting robots.txt

$robotstxt = get_option("kb_robotstxt");

if ( !$robotstxt)
return;

header("Content-type: text/plain");
print $robotstxt;
die;
}

धन्यवाद!

उत्तर:

उत्तर № 1 के लिए 1

आपको फ़ाइल को डेटा को सहेजना चाहिए, इसे ब्राउज़र में आउटपुट नहीं करना चाहिए। चेक आउट file_put_contents। आपको यह भी सुनिश्चित करना होगा कि फ़ाइल वेब सर्वर द्वारा लिखने योग्य है।