How do I add custom code to LifterLMS?

Why customize LifterLMS?

# Top

Customizing your LifterLMS setup allows you to tailor its functionality and appearance. This is especially useful if the settings in our core plugin, Add-ons, or themes do not support your unique requirements.

You can customize LifterLMS through code in a few ways:

  • Use an action or filter hook to modify or extend the plugin.
  • Use CSS to add design adjustments to frontend pages.
  • Completely override a frontend template with your own layout.

Customizing with PHP

# Top

You should never edit LifterLMS, our Add-ons, or your theme directly.

Changing any of the core code will keep you from updating LifterLMS when new versions become available. It’s important that you can update your plugins and theme when the author fixes bugs, shores up security, and adds new features.

There are two methods to add custom PHP to your LifterLMS website.

Both of these methods allow you to safely add customizations that will not be overwritten when a plugin or theme update is available.

Using the Code Snippets Plugin

# Top

The Code Snippets Plugin is available for free in the WordPress repository. The plugin provides a simple admin interface to add PHP, CSS, and JavaScript code to your WordPress site.

When using this plugin, you won’t need to add a customizations plugin or make any edits to your theme.

  1. Navigate to Plugins > Add New in the WordPress admin.
  2. Install and activate the Code Snippets plugin.
  3. In the menu, look for Snippets > Add New.
  4. Add a title that describes what the custom code will do on your website (this is only shown internally).
  5. In the “Code” section, write or paste in your custom code gist/recipe.
    1. When pasting in your code, note the <?php tag is already added by default. Do not add that line at the beginning of your code as it will trigger a fatal error.
    2. If there are any errors in your code, such as a missing comma, the editor will indicate an x sign in front of the line(s) of code with the error.
  6. By default, the “Run snippet everywhere” box is checked. Do not change this field unless you are sure you should.
  7. Click on Save Changes & Activate to run your custom code recipe on your WordPress site.
  8. Go test or view the customization that you added to your WordPress site.

Adding customization to your WordPress site can at first feel overwhelming, especially for the entry-level WordPress user. Although the Code Snippets Plugin has made this transition easier we recognize some users need help to use and implement custom code to their sites.

If you are having trouble using the Code Snippets Plugin or getting errors in your code recipe, please reach out to us for help.

Using the LifterLMS Customizations Plugin

# Top

If you would prefer to load your own custom plugin and use SFTP or FTP to upload code, we recommend starting with the LifterLMS Customizations Plugin.

  1. Download the LifterLMS Customizations plugin (lifterlms-customizations.zip file).
  2. Unzip the folder.
  3. Upload the folder to your site’s server in the /wp-content/plugins/ folder.
  4. Activate the plugin from the Plugins screen in the WordPress admin.

Once installed, you can use SFTP or FTP to access the plugin files and make changes.

Note: We do not recommend using the WordPress Plugin Editor to edit this customizations plugin.

Override a LifterLMS Frontend Template

# Top

If you wish to add template overrides via a customizations plugin, start by reading our template override documentation here.

Template overrides cannot be easily added using the Code Snippets method in this doc. You must be using a child theme or the LifterLMS Customizations example plugin to add a custom template.

Here’s how to override templates using the LifterLMS Customizations example plugin:

  1. Use SFTP or FTP to access your customization plugin in the server.
  2. Copy the LifterLMS templates you want to override into the /templates/ folder of this customizations plugin.
  3. Modify the PHP templates as needed.
  4. Upload the updated template to your server.
  5. In the main lifterlms-customizations.php plugin file, activate the llms_customizations_overrides_directory function by removing the commented out add_filter() line directly below this function.

This filter is commented out by default to prevent unnecessary override checks to an empty directory.

Last Updated on
Was this article helpful?