Слышал, что в файл function.php WordPress следует добавить какой-то собственный скрипт. шаблон, который я использую, однако этот файл состоит из 8800 строк кода, и я не уверен, где именно его разместить, вот код:
Код: Выделить всё
add_action( 'after_setup_theme', 'et_setup_theme' );
// Add MongoDB connection code after theme setup
function et_setup_mongodb() {
// Establish MongoDB connection
$mongoUri = 'mongodb://localhost:27017';
$dbName = 'your_database_name';
$client = new MongoDB\Client($mongoUri);
$db = $client->$dbName;
// Perform MongoDB operations here
// Example: Insert document into MongoDB collection
$collection = $db->your_collection_name;
$result = $collection->insertOne([
'name' => 'John Doe',
'email' => 'john@example.com',
'age' => 30
]);
if ($result->getInsertedCount() > 0) {
echo "Document inserted successfully";
} else {
echo "Error: Failed to insert document";
}
}
add_action( 'after_setup_theme', 'et_setup_mongodb', 20 ); // Adjust priority as needed
Подробнее здесь: https://stackoverflow.com/questions/782 ... ss-website