我想在Wordpress出现之前运行一个脚本。
我知道这是错误的,但目前我在index.php
以下代码之前的文件:
{{{MY FUNCTION IS HERE}}}
require \'vendor/autoload.php\';
use GeoIp2\\Database\\Reader;
session_start();
if (!isset($_SESSION[\'country\'])) {
$reader = new Reader(\'db/GeoLite2-Country.mmdb\');
$record = $reader->country($_SERVER[\'REMOTE_ADDR\']);
$_SESSION[\'country\'] = $record->country->isoCode;
}
{{{MY FUNCTION ENDS HERE}}}
/**
* Front to the WordPress application. This file doesn\'t do anything, but loads
* wp-blog-header.php which does and tells WordPress to load the theme.
*
* @package WordPress
*/
/**
* Tells WordPress to load the WordPress theme and output it.
*
* @var bool
*/
define( \'WP_USE_THEMES\', true );
/** Loads the WordPress Environment and Template */
require( dirname( __FILE__ ) . \'/wp-blog-header.php\' );
当Wordpress更新时,这显然被掩盖了,所以我如何才能安全正确地包含我的函数呢?
在我的主题中,我尝试了以下内容functions.php
文件:
add_action( \'init\', \'my_script\' );
function my_script() {
// my script here
}
但这还不够快,除非我犯了个错误?
有人能帮忙吗?
非常感谢