0

The contents of the /index.php is as follows:

/**
 * 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' );

If I make any changes in this file, then do a Wordpress Update, will the contents of this file be replaced? I've not been able to find any references online for this file, only Wordpress' /wp-includes and /wp-admin folders.

I don't have access to the php.ini file and want to change the session cookie lifetime setting by adding the following code:

    $seconds = 31557600; //1 year
    ini_set('session.gc_maxlifetime', $seconds);
    ini_set('session.cookie_lifetime', $seconds);

but don't want to add it to a file that potentially could be overridden in a couple of months time.

2 Answers 2

4

Yes, index.php is part of core and is liable to be overwritten.

In fact, if you look at the process to manually update WordPress, step 7 is:

Upload all new loose files from the root directory of the new version to your existing WordPress root directory

That may include index.php.

You can put custom PHP code in a custom plugin or theme. If using a pre-built theme, first create a child theme and then put your code in that child theme's functions.php.

1

If you run PHP as Apache module you can set php.ini values in .htaccess:

AllowOverride Options
php_value session.gc_maxlifetime 31557600
php_value session.cookie_lifetime 31557600
3
  • I tried that but got a 500 internal server error. Mar 19, 2019 at 10:25
  • You can create a *.php file with <?php phpinfo(); ?> which will give you all the information about your PHP configuration. This way you' ll figure out is your PHP an Apache module or CGI module.
    – Max Yudin
    Mar 19, 2019 at 20:18
  • Also, may be you have to read about AllowOverride, but it's out of WordPress scope.
    – Max Yudin
    Mar 19, 2019 at 20:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.