Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 11

WordPress Codes

Permalink Code:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

==================================================================

Different codes to be added in php.ini file (PHP 7 or above


version):
extension=propro.so
extension=raphf.so
extension=ctype.so
extension=xmlwriter.so
extension=imagick.so
extensindeion=mcrypt.so
extension=bcmath.so

==================================================================

IMagick is supported in PHP 7.4

Need to add below code:


extension=imagick.so
==================================================================

Code to disable mod_security (need to be add in .htaccess file)


(not recommended)
<IfModule mod_security.c>
SecFilterEngine Off
SecFilterScanPOST Off
</IfModule>
===================================================================
===========

Home/Site URL Define Code: Add it in the wp-config.php


301
define( 'WP_SITEURL', 'https://example.com/' );

define( 'WP_MEMORY_LIMIT', '256M' );


define('WP_DEBUG_DISPLAY', false);

define('WP_DEBUG', true);
===================================================================

Disabling Automatic WordPress Updates : Add it in the wp-


config.php

define( 'WP_AUTO_UPDATE_CORE', false );

==================================================================

#Leverage browser cache add in .htaccess file


<IfModule mod_expires.c>
ExpiresActive On

# Images
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType imindage/gif "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType image/webp "access plus 1 year"
ExpiresByType image/svg+xml "access plus 1 year"
ExpiresByType image/x-icon "access plus 1 year"

# Video
ExpiresByType video/mp4 "access plus 1 year"
ExpiresByType video/mpeg "access plus 1 year"

# CSS, JavaScript
ExpiresByType text/css "access plus 1 month"
ExpiresByType text/javascript "access plus 1 month"
ExpiresByType application/javascript "access plus 1 month"

# Others
ExpiresByType application/pdf "access plus 1 month"
ExpiresByType application/x-shockwave-flash "access plus 1 month"
</IfModule>
===================================================================

Cookies are blocked or not supported by your browser. You


must enable cookies to use WordPress.
Add below code in the functions.php file of theme.

setcookie(TEST_COOKIE, 'WP Cookie check', 0, COOKIEPATH,


COOKIE_DOMAIN);
if ( SITECOOKIEPATH != COOKIEPATH ) setcookie(TEST_COOKIE,
'WP Cookie check', 0, SITECOOKIEPATH, COOKIE_DOMAIN);

OR
Add below code in wp-config.php WP Dashboard cookie error

define('ADMIN_COOKIE_PATH', '/');
define('COOKIE_DOMAIN', '');
define('COOKIEPATH', '');
define('SITECOOKIEPATH', '');

===================================================================
Code to deny a specific file (ex: config.php):

<Files config.php>
order allow,deny
Deny from all
</Files>
==================================================================
How to comment a deny code:
#<Files config.php>
#order allow,deny
#Deny from all
#</Files>

===================================================================

To repair and optimize database: Add it in the wp-config.php


define( 'WP_ALLOW_REPAIR', true );

Once added, please access wp-admin/maint/repair.php

Example: http://wprt.nhtipage.com/wp-admin/maint/repair.php
Just don’t forget to remove the line WP_ALLOW_REPAIR from wp-
config.php when you’re done.
=======================================================
For older PHP versions, The SQL adapter or the DB type was mysql. However for PHP 7.2 and
above we need to change it to mysqli. So changing it to mysqli will fix most of the broken PHP
websites depending on which website builder has been used.
mysql_connect() does not work on newer versions of PHP. Confirm the
PHP version set in the account and take permission from the
customer to switch it to an older version of PHP say 5.3/5.5/5.6.
=========================================================
Htaccess Codes: https://www.htaccessredirect.net/

Test script to test database connection. Create file dbtest.php and add
below code
Note: Make sure to replace the localhost with database hostname,
username with db username and password with database password

<?php
$servername = "localhost";
$username = "username";
$password = "password";
c // Create connection
$conn = new mysqli($servername, $username, $password);

// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>
==========================================================
To resolve Mixed Content issue with SSL : add it in the .htaccess file
Header always set Content-Security-Policy: upgrade-insecure-requests
==========================================================
Redirect http to https: add it in the .htaccess file (301)
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

==========================================================
phpinfo Code: create a new file with name phpinfo.php
<?php
phpinfo();
?>

==========================================================

http://saravanapriya14058.ipage.com/sessiontest.php
Testing session path. Create a file sessiontest.php and add below code
<?php
session_start();
header("Cache-control: private"); //IE 6 Fix
if(!$_SESSION['count']){
$_SESSION['count'] = 1;
} else {
$_SESSION['count']++;
}
echo $_SESSION['count'];
?>
======================================================

Enable Gzip Compression code; Add it in .htaccess file


#enable Gzip compression
<IfModule mod_deflate.c>
# Compress HTML, CSS, JavaScript, Text, XML and fonts
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
AddOutputFilterByType DEFLATE application/x-font
AddOutputFilterByType DEFLATE application/x-font-opentype
AddOutputFilterByType DEFLATE application/x-font-otf
AddOutputFilterByType DEFLATE application/x-font-truetype
AddOutputFilterByType DEFLATE application/x-font-ttf
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE font/opentype
AddOutputFilterByType DEFLATE font/otf
AddOutputFilterByType DEFLATE font/ttf
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE image/x-icon
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/xml

# Remove browser bugs (only needed for really old browsers)


BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
Header append Vary User-Agent
</IfModule>
=========================================================

The default limit of upload_max_filesize and post_max_size is 20 MB.


However, we can increase these directives up to 50 MB in shared.

The default and maximum limits for max_execution_time and


max_input_time are 120 seconds.
upload_max_filesize: 50 MB
max_execution_time: 120 seconds
max_input_time : 120

post_max_size = 50M

==========================================================

Wordpress index.php file code :

<?php
/**
* 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('./wp-blog-header.php');
?>

==========================================================
Automatic WordPress Updates Disabling:
Add below code in the wp-config.php file:
define( 'WP_AUTO_UPDATE_CORE', false );

Disable automatic WordPress plugin updates:


add_filter( 'auto_update_plugin', '__return_false' );

Disable automatic WordPress theme updates:


add_filter( 'auto_update_theme', '__return_false' );

You might also like