1. Go to this page and download the library: Download lxbdr/wp-template-helper 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/ */
if ($template->has('user.profile')) {
// Access nested data
}
if ($template->notEmpty('user.bio')) {
// Value exists and is not empty
}
if ($template->empty('user.location')) {
// Value is empty or doesn't exist
}
// Safe HTML output with entities escaped
$template->html('user.name');
// Allow specific HTML tags (wp_kses_post)
$template->safeHtml('user.profile.bio');
// In HTML attributes
<a href=" $template->url('user.profile.url');
// Access deeply nested data
$template->html('user.settings.preferences.theme');
// Clean and secure template code
<div class="user-profile">
<h2> $template->html('user.name');
$userName = $template->_html('user.name');
$profileUrl = $template->_url('user.profile.url');
// Use in complex logic
if ($template->has('user.profile') && $template->_url('user.profile.url')) {
// Process data
}
// Instance usage
$template = new WpTemplateHelper([
'title' => 'My Page',
'content' => 'Page content'
]);
// Echo the ID
<div id=" $template->id('header');
$template = new WpTemplateHelper([]);
$prefix = $template->getIdPrefix(); // e.g., "abc12-"
// Useful for coordinating IDs with aria-labels or other references
<button id=" $template->id('trigger');
// In your theme's functions.php or plugin file
add_action('wp_head', function() {
echo '<style>' . WpTemplateHelper::getAdvancedImgCss() . '</style>';
});
// Or via enqueue scripts to attach it to an existing handle
add_action('wp_enqueue_scripts', function() {
$style = \Lxbdr\WpTemplateHelper\WpTemplateHelper::getAdvancedImgCss();
wp_add_inline_style('wp-block-library', $style);
});
\add_action( 'acf/init', function () {
\Lxbdr\WpTemplateHelper\WpTemplateHelper::registerAdvancedImgAcfFields();
} );