PHP code example of calderawp / file-locator

1. Go to this page and download the library: Download calderawp/file-locator library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

calderawp / file-locator example snippets


    //Load a file called "food.html" from current themes "templates" folder
    $file = calderawp_file_locator( 'templates/food.html' );
    if ( is_string( $file ) ) {
        echo $file;
    }
    
    //load a php file from your plugin, if a file "noms.php" of same name is not in template
    $file = calderawp_file_locator( 'noms.php' );
    
    //By default only file extensions php|html|htm are allowed.
    //TO override this use the "calderawp_file_locator_allow_extensions" filter before calling it, like this:
    add_filter( 'calderawp_file_locator_allow_extensions', function( $allowed, $context ) {
    	if ( 'slug_json_loader' === $context ) {
    		$allowed = array( 'json' );
    	}
    
    	return $allowed;
    
    }, 10, 2 );
    
    return calderawp_file_locator( 'hats.json', 'slug_json_loader' );
    
    //Use a special single-{$post-type}.php, in this case single-hat.php from plugin if theme/child theme doesn't have that file.
add_filter( 'template_