Internal 500 error after directory renaming

Today in one client’s web hosting (it is Nexcess, but same problem can appear in another hostings using the same technology) i needed to rename WordPress home directory. (It was installed in a sub-directory)

I renamed directory, then modified .htaccess file, and then i changed siteurl and home options in wp_options table.

These simple steps above are quite enough for making WP to work in new directory. But i started getting strange errors instead.

Fatal error: require_once(): Failed opening required ‘/chroot/home/sitename/OLDNAME/wp-blog-header.php’ (include_path=’.:/opt/…/php’) in /chroot/home/sitename/OLDNAME/wp-blog-header.php on line 52

I have checked cache layers (all cache layers were turned off at that time) and configurations. Nothing wrong. Everything was provided correctly. Then i tried to print directory name before the line

require( dirname( FILE ) . ‘/wp-blog-header.php’ );

at index.php file. After saving and testing i saw that above error was solved and i started getting the same error for another file:

Fatal error: require_once(): Failed opening required ‘/chroot/home/sitename/OLDNAME/wp-load’ (include_path=’.:/opt/…/php’) …

This time wp-load.php can’t be loaded. At this time i figured out that there is some hosting based software which can’t be refresh itself after renaming directory (BTW, apache or httpd restart doesn’t help in this case) – but if you modify the file, it pings that software and that file starts to be recognized by webserver.

So there were two ways in order to solve the problem under those conditions.

  • To modify thousands of WP files one by one – which would be stupid time wasting.
  • To send some “ping” to all files. – That’s what i did. I opened SSH command line and run this command:

find -type f -exec touch {} +

This command doesn’t modify any file, it just modifies their timestamp data which is quite enough in our case.

After running this command the website started working normally under its new name.

WordPress AMP Plugin – Use Adsense in Classic Mode

There are 2 popular AMP plugins for WordPress:

  1. Official WordPress AMP plugin: AMP
  2. 3rd party AMP plugin: AMP for WP

AMP for WP should have an option for Adsense. But official one not.

I have made small inspection and noticed that all existing adsense codes are converted to amp tags – without any issues. But there is not any Ads JS file which should render these tags.

Its documentation is not good and doesn’t provide easy to fix information about this.

First i tried to add the needed JS code (for all type of ads) and tag (for auto-ads) correspondingly with wp_head and wp_footer native hookd. But no luck.

Classic mode of AMP plugin doesn’t fire any UI hook. Because it has own small template file.

So i decided to inspect the plugin’s code and to see which hooks it has for own small template.

Continue reading “WordPress AMP Plugin – Use Adsense in Classic Mode”

Solving slowness of php mail() function

If you suddenly noticed that mail() functions works very slowly and causes long page loads, here is quick solution.

By default php mail() functions works via SendMail service which requires having correct hostname at your server.

You can check it by typing hostname

in SSH terminal.

You probably will see something like ubuntu-16gb-nb1-1 or centos-4gb-cl1 etc.

But you must have correct hostname there. Type this command and it will set correct hostname.

hostname yourwebsite.com

After getting correct hostname add newly added one to /etc/hosts.

Open /etc/hosts with

nano /etc/hosts

command and you will see the line like

127.0.1.1 ubuntu-16gb-nb1-1  ubuntu-16gb-nb1-1

Comment or remove that line and add this line instead

127.0.0.1 localhost.localdomain localhost yourwebsite.com

Save it by clicking CTRL+O and that’s all. Test mail() function again, it will work as fast as rocket.

How to keep social share counts after migrating to SSL

When you migrated your website to SSL protocol (from http to https), you probably noticed that you had lost all your previous share counts. How to keep them?

We can think on different approaches for them.

Main point: Unfortunately it is not possible via social networks APIs themselves. That’s why we need some tricks.

Here is how i solved this problem and retained back to my old posts’ social share counts.

I am using custom embed codes for social share buttons. Here is facebook embed code i am using:

Now we need to apply our trick and to retain old share counts.

Here is the logic:
1. We remember the date we migrated to SSL.
2. We check if current post was published before or after that date.
3. If it is published before that date, we pass Facebook our URL with HTTP version, in order to save old share counts.

That’s all.
I have migrated to SSL at 20th May, 2018. That’s why i check if post_date is greater or less than 2018-05-20 06:30:03, if it is less, then i change HTTPS to HTTP.

 

Before:

After:

It is possible to apply same logic to other social network embed codes.

WordPress Search – Redirect plural search terms to singular ones

Today I am sharing quick gist which can redirect plural search terms to the results with singular search terms.
Here is when it can be useful:
Let’s say you have some article/page/product which contains the word “e-book”. But your visitor enters your website and searches for the term “e-books”. By default search algorithm he/she will get “not found” message. Continue reading “WordPress Search – Redirect plural search terms to singular ones”