Skip to main content
1 of 3
Antti Koskinen
  • 5.9k
  • 8
  • 15
  • 26

If you're getting a "class not found" warning, then maybe the class file hasn't just been included/loaded when you're trying to instantiate the class. So perhaps you could try requiring/including the class file inside your shortcode function when it's needed. Something along these lines,

function se_menu_shortcode( $atts, $content = null ) {

  // extract

  if ( ! class_exists('wp_bootstrap_navwalker') ) {
    require_once 'path/to/class/definition/file.php';
  }

  // return
}

Or maybe you could try writing an autoloader for handling the requiring/including of classes automatically, https://www.php.net/manual/en/function.spl-autoload-register.php

Antti Koskinen
  • 5.9k
  • 8
  • 15
  • 26