WordPress Frequently Asked Questions

What is a Child Theme ?

Child Themes are “extensions” of an already existing WordPress template. In object terms, Creating a child theme, allows you to edit or add functionality to your template without having to overwrite any of the parent theme files, risking making mistakes or losing your job when you make updates. Otherwise, if you make changes directly to the Theme, the next Theme update will wipe out all of your changes.

I like to use the Child Theme Generator plug-in to accomplish this. It allows you to create multiple children, although just one is generally enough. To create a child theme, follow these steps:

  1. Make a backup of your website !!!
  2. Install the Child Theme Generator plug-in and Activate it.
  3. You will find Child Theme Generator in the DashBoard tab under Settings as Child-Theme-Gen. Click it.
  4. Select your parent theme, fill out the form fields and the plugin will create a child theme for you.
  5. It is recommended that you name your Child Theme “Original-Theme-name-Child”, so for Theme Twenty-Twenty, you would name your child theme Twenty-Twenty-Child.
  6. Now you will need to make some edits to the new child theme directory. Use whatever tool you normally use to work with files, be it: cPanel, FTP, WEBDEV, ssh, etc.
  7. You must now create the following files under your wp-content/themes/your-theme-child directory (Child-Theme-Generator will have created this directory.)
  8. You will notice that Child Theme Generator has put a file, screenshot.png, in the directory. This is the picture used for the Appearance Themes page.
  9. Create a file called style.css with the following code in it to inherit all of the parent theme’s CSS:
    1. <?php
      add_action( ‘wp_enqueue_scripts’, ‘my_theme_enqueue_styles’ );
      function my_theme_enqueue_styles() {
      $parent_style = ‘parent-style’;
      wp_enqueue_style( $parent_style, get_template_directory_uri() . ‘/style.css’ );
      wp_enqueue_style( ‘child-style’, get_stylesheet_directory_uri() . ‘/style.css’,
      array( $parent_style ), wp_get_theme()-&amp;gt;get(‘Version’);

      }
      ?>
  10. If you have any other CSS that you need to add,, put it after the code above.
  11. Lastly, file functions.php to the child-theme directory. Child-Theme-Generator will add the following PHP code:
    1. <?php
      /*This file is part of twenty-twenty-child, twenty-twenty base child theme.
      All functions of this file will be loaded before of parent theme functions.
      Learn more at https://codex.wordpress.org/Child_Themes.
      Note: this function loads the parent stylesheet before, then child theme stylesheet
      (leave it in place unless you know what you are doing.)
      */function education_base_child_enqueue_child_styles() {
      $parent_style = ‘parent-style’;
      wp_enqueue_style($parent_style, get_template_directory_uri() . ‘/style.css’ );
      wp_enqueue_style( ‘child-style’, get_stylesheet_directory_uri() . ‘/style.css’,
      array( $parent_style ),
      wp_get_theme()->get(‘Version’) );
      }
      add_action( ‘wp_enqueue_scripts’, ‘education_base_child_enqueue_child_styles’ );
  12. You can add your own functions to functions.php after the above code. For example:
    1. if ( ! function_exists( ‘disable_admin_bar’ ) ) :
      function disable_admin_bar() {
      if (is_user_logged_in() && (! current_user_can(‘subscriber’))) {
      show_admin_bar(true);
      } else {
      show_admin_bar(false);
      }
      }
      endif;
      add_action(‘init’, ‘disable_admin_bar’);
  13. Now select your child theme as your active theme in Appearance > Themes
  14. And you are done.

 

 

How can I make external links open in a new tab or window ?

There are two ways to force external links to open in a new tab or window:

The hard way.

The “Open in New Window” checkbox in “Open link in a new tab” (the chain link in the editor), does not always work. Therefore in order to sure that the link appears in a new window or tab, you must code the link in the following JavaScript.

<a onclick=”window.open (‘YourLinkURL‘, ‘_blank’);” href=”javascript:void(0);”>Text for MyLink</a>

The Easy Way

There is a very nice WordPress plug-in “Open in New Window Plugin“. Any link that is not pointed to your website, will automatically open in a new tab or window. And that is all there is to it.

 

What is a good WordPress backup ?

After doing an extensive review, I really like, use and recommend UpdraftPlus Backup/Restore. It schedules itself to run automatically, it does a complete backup of your database, themes, plug-ins, media, etc.

UpdarftPlus will also move your backups to remote cloud storage such as DropBox, Google Drive, an FTP server of your choice, multiple storage sites, etc. It also will clean up after itself by deleting old backups beyond the limit you set. You can do all of the above with the free version.

Restores are very simple to perform and UpdraftPlus checks thoroughly before the restore is done. With the addition of either the UNIX sed command or better, the Better Search and Replace plug-in.

SEO tells you that you are missing an H1 or H2, but your theme won’t let you ?

Recently, I ran into a template related issue. It took over control of <h1> and <h2>. Essentially the home page was suppressed. SEO will penalize you for having more than 1 <h1>, but you can have several <h2>s. Using the HTML Widget, I managed to insert them into the homepage. The result works very well, inspect my site’s home page, and see if you can find them.

<h1 style="color:transparent;font-size:0px;">Aldersoft - We can help with all of your computing needs</h1>
<h2 style="color:transparent;font-size:0px;">Serving the computing needs of the Winnipeg, East St Paul and Selkirk areas.</h2>

What is the best SEO Tool ?

For all practical purposes, you can never just use one SEO tool. On the WordPress side of the equation, I use either RankMath or All-in-One-SEO plugins to gather the SEO information and to generate my sitemap.xml. From a usage perspective,

Personally I like using RankMath as it immediate feedback inside the editing process helps tune your site with “on-the-spot” visual feedback. Also, it is relatively new, thus it avoids carrying all the baggage of old SEO tools.

All-in-One-SEO pack does an excellent job and is quite comprehensive and well supported. It, however, lacks the visual feedback features of RabkMath.

From an analysis standpoint, RankMath SEO Analyzer does a nice job of ranking your website and also has a good diagnostics report that you can use to follow up on SEO issues.

Another good analysis product is SiteChecker Pro. SiteChecker Pro free version will generate a very thorough report about SEO issues to be addressed.

A great tool for watching how your webpages are working and for diagnosing tricky SEO problems is Screaming Frog Spider. It is invaluable in tracking down bad links, redirects, and HTTP errors.

I received a recommendation recently about a great set of tools from WebsitePlanet.com . Gracias Diana Gonzales-Ester por su recomendación. Their collection of free tools is impressive and handy. Of note are: Redirect Tracking (to make sure things are going where you think they are), XML Sitemap Checker (validates your sitemaps), Robots.txt Tester (validates your robots.txt),  Responsive Design Check which I really liked, as it will render your site on several different cell phones, tablets, and laptops eg. iPhone X, 8, iPad, Samsung Galaxy S7, ASUS Nexus 7, Kindle Fire, etc. SSL Checker does a good job verifying your certificate and its proper installation. And much more. Give it a try, it is a great selection of tools.

Why do I keep getting “too many redirects” when I retrieve the Home Page, but not any other page ?

This can be caused by a number of things, however, if you use more than one “environment” under your registered website name, this solution should fix this for you. Also, if you have recently switched from Plain PermaLinks to %postname% PermaLinks or others, you may run into this problem as well.

 

By “environments”, I mean things like test, devl, next (stage), prod, etc. These are normally called sub-domains. They could also be different language translations. EG. en, fr, es, ru, etc. Regardless, the situation results in too many redirects as WordPress does not automatically redirect to index.php when the URL ends with a directory name with or without a trailing /, resulting in an infinite loop.

 

For example: If you have registered MySite.com, the internet will direct your request to where your main site is located. EG. https://MySite.com. You may have two environments, stage and prod, which is quite common and strongly recommended. Stage is where you make your changes and test them, prod is your environment that the world sees.


Hence you have two WordPress installations: https://MySite.com/stage and https://MySite/prod. You normally want prod to be your “goto” WordPress site, so you put a redirect into the MySite.com “home” directory to send people automatically to prod. For example, you would create an index.php file in your home directory which contains the following redirect. (Note. The home directory is usually public_html in your cPanel File Manager.)

<?php
/* Redirect to MySite.com/prod with a permanent redirect */
header( ‘Location: https://MySite.com/prod/’, TRUE, 301 );
?>

You can access the other directories using the URL request. EG. https://MySite.com/stage. Generally, this will partially work if you include a page name. EG. https://MySite.com/stage/about_us, however, the directives that WordPress inserts by default, break when no page name is specified. EG. https://MySite.com/stage or https://MySite/stage/ and https://MySite.com/prod or https://MySite.com/prod and since you have the redirect in the home directory, https://MySite.com or https://MySite.com/.


Using our example, you need to add the following to the beginning of the .htaccess file in public_html/stage.

# BEGIN Aldersoft Permalink fix
# Fix WordPress Permalink bug for URLS, not including index.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule .* – [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteRule ^$ https://%{HTTP_HOST}/stage/index.php [R,L]
RewriteRule ^(.*)%{HTTP_HOST}$ $1%{HTTP_HOST}/stage/index.php [R,L]
RewriteRule ^(.*)%{HTTP_HOST}/$ $1%{HTTP_HOST}/stage/index.php [R,L]
</IfModule>
#END Aldersoft Permalink Fix

and also the following needs to be added to the beginning of your .htaccess in public_html/prod.

# BEGIN Aldersoft Permalink fix
# Fix WordPress Permalink bug for URLS, not including index.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule .* – [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteRule ^$ https://%{HTTP_HOST}/prod/index.php [R,L]
RewriteRule ^(.*)%{HTTP_HOST}$ $1%{HTTP_HOST}/prod/index.php [R,L]
RewriteRule ^(.*)%{HTTP_HOST}/$ $1%{HTTP_HOST}/prod/index.php [R,L]
</IfModule>
#END Aldersoft Permalink Fix

This essentially says:

  • Is the Apache rewrite module loaded?
  • If so, then start the Rewrite Engine
  • Set the URL pointer to the end of the start of the
  • If there was no data passed following the home directory,
    Then rebuild the URL to point to https://MySite.com/prod/index.php
    EG. https://MySite.com/prod will have %{HTTP_HOST} of “MySite.com”
    This will be rebuilt as https://MySite.com/prod/index.php
    Lastly [R,L], says redirect (302) to the new URL, leave .htaccess, and start again.
  • If the URL ends immediately after the %{HTTP_HOST} EG. https://MySite.com or https://MySite.com/prod
    Then rebuild the URL to point to https://mysite.com/prod/index.php
    Lastly [R,L], says redirect (302) to the new URL, leave .htaccess, and start again.
  • If the URL ends with a / immediately after the %{HTTP_HOST}/ EG. https://mysite.com/prod/
    Then rebuild the URL to point to https://MySite.com/prod/index.php
    Lastly [R,L], says redirect (302) to the new URL, leave .htaccess, and start again.

Note. Thank you Jacob Buller of EcoVillages.CA for your help in debugging this.