The error Fatal error: Uncaught Error: Using $this when not in object context
means that something is referencing a Class/Object with $this
, while there's no Class/Object in the current scope.
If the code you posted:
function search_shortcode() {
return '<div class="genesis-404-search">' . get_search_form( false ) . '</div>';
}
// Add shortcode for search form in Genesis Framework
add_shortcode( 'genesis-404-search', array( $this, 'search_shortcode' ) );
Is wrapped in a Class like so: class Some_Class { /* Your Code */ }
then something else is at play.
If not, and it's just native like you posted, replace:
add_shortcode( 'genesis-404-search', array( $this, 'search_shortcode' ) );
with
add_shortcode( 'genesis-404-search', 'search_shortcode' );
WordPress allows you to reference classes with callback functions, which is what the original code is attempting to do. But if there's no class to reference, then you just use the callable function name. I'd also consider replacing the function name to something a bit more unique since you're not in a Class or Namespace, and search_shortcode
may result in a naming conflict for being so generic:
function so_53052312_search_shortcode() {
return '<div class="genesis-404-search">' . get_search_form( false ) . '</div>';
}
// Add shortcode for search form in Genesis Framework
add_shortcode( 'genesis-404-search', 'so_53052312_search_shortcode' );