Hey, I am putting together list of links to code that I have found so very helpful when building wordpress and woocommerce websites.

I can’t stand plugins because they slow a website down so badly. It is super easy to add in code that solves this problem, straight onto the site.  It is very simple and if it doesn’t work – I will tell / show you how to fix it. The main thing is to be brave and experiment!

Logging errors on the site

Ok so you keep getting a white screen or grey one saying there is a problem. Don’t panic!

  • Get hold the hosting log-in details
  • Get into the public_html folder
  • Find wp_config file
  • Find the code that says this:
    define('WP_DEBUG', false);
  • Replace it with this:
    define( 'WP_DEBUG', true );
    define( 'WP_DEBUG_DISPLAY', false );
    define( 'WP_DEBUG_LOG', true );
  • Note that I have set wp_debug_display to false. This stops the errors showing on the frontend. If you are working a staging site then by all means change false to true.
  • In the meantime your errors are going to be logged here: /wp-content/debug.log
  • You can then go and view the log or download it
  • Don’t let this file get too big for the sake of your client’s hosting.
  • This is a link to the wordpress debugging page for further info

What do the errors mean

PHP Fatal error: Allowed memory size

[08-Aug-2024 16:05:57 UTC] PHP Fatal error:  Allowed memory size of 134217728 bytes exhausted (tried to allocate 45056 bytes) in /home/fake/madeupurls.co.za/wp-includes/functions.php on line 14334

The website has exhausted the memory that has been allocated to it temporarily. It should be ok again in a few minutes.  Just work slower.

How do I fix allowed memory size

Ask the host to up it, ask the host what the client’s options are to fix this – watch out if they just want to upgrade your package but not increase your memory which they love to do.  Think about sharing a VPS or getting your own. Then you can control the memory issue.  Will have to tell you at a later stage how to do this if you aren’t sure at this moment in time.

Or read these suggestions on how to fix your exhausted memory:

  1. Edit your wp_config file – add below just before …..stop editing….happy…something
    define( 'WP_MEMORY_LIMIT', '256M' );
  2. Edit .htaccess
  3. Check php.ini

View image dimensions and file size in columns

This is a favourite of mine and this guy kills it with his giude on how to show image dimensions quickly in admin.  He also has a post on how to show the file sizes. He has included code so you can sort the columns and you can use the checkbox under screen options to hide the columns.

Translate your website into a different language

This is how you translate your site into a different language using ai

 

How to style Woocommerce notice?

.woocommerce-message{
background: red;
}

Add your css code to Appearance/Theme Editor/style.css – make sure its the child theme

Woocommerce Speed

Improve your woocommerce speed

Auto update the copyright year on your website

AI generated help from chatgpt says and i’m testing on this website or if you dont want to AI it here’s a further break down of how to auto update your copyright year

To automatically update the copyright year in WordPress without using a plugin, you can edit your theme’s footer file (footer.php) to use PHP code that dynamically displays the current year. Here’s a step-by-step guide:

  1. Access Your Theme’s Footer File:
    • Go to your WordPress Dashboard.
    • Navigate to Appearance > Theme File Editor.
    • In the right sidebar, find and click on footer.php.
  2. Add the Dynamic Copyright Code:
    • Look for the section where the copyright notice is written. It usually looks something like this:

      php

      <p>&copy; 2023 Your Site Name. All rights reserved.</p>
  3. Replace the Static Year with Dynamic PHP Code:
    • Change the static year to a PHP snippet that automatically updates the year:

      php

      <p>&copy; <?php echo date('Y'); ?> Your Site Name. All rights reserved.</p>
  4. Save the Changes:
    • Click the Update File button to save your changes.

Explanation:

  • <?php echo date('Y'); ?> is a PHP function that outputs the current year.

Optional: Display a Range of Years

If you want to display a range of years (e.g., 2010–2024), use the following code:

php

<p>&copy; 2010<?php echo date('Y'); ?> Your Site Name. All rights reserved.</p>

This method ensures that your copyright year stays up to date automatically!

OR you if you are using Divi Builder to create a footer template then do this also thanks to AI for generaing this and it works!

Since you’re using Divi’s Theme Builder to create your footer, changes made directly in the footer.php file won’t affect the footer output. To add a dynamic copyright year in your Divi Theme Builder footer, you’ll need to use a Code Module within your Divi footer layout. Here’s how to do it:

Steps to Add Dynamic Copyright Year in Divi Theme Builder:

  1. Open Divi Theme Builder:
    • Go to your WordPress Dashboard.
    • Navigate to Divi > Theme Builder.
  2. Edit Your Footer Template:
    • Find your custom footer template and click on the Edit icon (pencil) to modify it.
  3. Add a Code Module:
    • Inside the Footer section, add a Code Module where you want the copyright notice to appear.
  4. Insert the Dynamic Copyright Code:
    • In the Code Module, paste the following code:
      php

      <p>&copy; <?php echo date('Y'); ?> Your Site Name. All rights reserved.</p>
  5. Save the Changes:
    • Click Save inside the Code Module.
    • Click the green Save button at the top right of the Theme Builder to save your footer layout changes.

Alternative with Shortcode:

If the PHP code does not render directly in the Code Module, you can use a shortcode instead:

  1. Add the PHP Code to Functions.php:
    • Add the following code to your theme’s functions.php file (preferably a child theme):
      php

      // Function to display current year for copyright
      function display_copyright_year() {
      return '&copy; ' . date('Y') . ' Your Site Name. All rights reserved.';
      }
      add_shortcode('copyright_year', 'display_copyright_year');
  2. Use the Shortcode in Divi’s Code Module:
    • Go back to the Code Module in the Divi Theme Builder and insert this shortcode:
      html

      © 2007- 2024 WEB DESIGN CAPE TOWN SOUTH AFRICA All rights reserved.

These methods will let you dynamically display the current year in your Divi-built footer!