PHP code example of builtnorth / wp-utility
1. Go to this page and download the library: Download builtnorth/wp-utility 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/ */
builtnorth / wp-utility example snippets
if (class_exists('BuiltNorth\WPUtility\App')) {
$utility = BuiltNorth\WPUtility\App::instance();
$utility->boot();
}
use BuiltNorth\WPUtility\Components\Component;
Component::accessibleCard(
url: 'https://example.com',
title: 'Card Title',
new_tab: true,
class: 'custom-card-class'
);
Component::breadcrumbs(
show_on_front: true,
class: 'breadcrumbs',
separator: '»',
home_title: 'Home',
prefix: 'You are here:',
nav_attributes: '', // Optional. Block wrapper attrs for <nav> (e.g. get_block_wrapper_attributes()).
);
Component::button(
button_type: 'a',
class: 'btn',
extra_class: 'custom-btn',
style: 'primary',
size: 'large',
appearance: 'fill',
text: 'Click Me',
link: 'https://example.com',
target: '_blank',
screen_reader: 'Opens in new window',
attributes: ['data-tracking' => 'button-click'],
icon: '<svg>...</svg>',
icon_position: 'left'
);
$screen_reader = Button::resolve_screen_reader_text([
'explicit' => 'about our services',
'text' => 'Learn more',
'link' => $url,
'post_id' => get_the_ID(),
'is_permalink' => false,
'opens_in_new_tab' => true,
'text_domain' => 'my-plugin',
]);
Component::button(
// ...
screen_reader: $screen_reader,
);
Component::image(
id: 123,
class: 'featured-image',
additional_classes: 'rounded shadow',
custom_alt: 'Custom alt text',
show_caption: true,
lazy: true,
wrap_class: 'image-wrapper',
Component::pagination(
query: $custom_query // WP_Query object (optional, uses global $wp_query if not provided)
);
use BuiltNorth\WPUtility\Utilities\Utility;
Utility::archiveUrl();
$countries = Utility::countryList();
// Returns: ['US' => 'United States', 'CA' => 'Canada', ...]
Utility::getTerms(
post_id: get_the_ID(),
taxonomy: 'category',
taxonomy_link: true,
first_term_only: false,
class: 'post-terms'
);
$title = Utility::getTitle();
$should_lazy = Utility::lazyLoadFirstBlock(
block: $block,
non_lazy_parents: ['core/columns', 'core/group'],
default_lazy: true
);
$minutes = Utility::readingTime();
$states = Utility::stateList();
// Returns: ['AL' => 'Alabama', 'AK' => 'Alaska', ...]
use BuiltNorth\WPUtility\Helpers\Helper;
$safe_svg = Helper::escapeSvg($svg_content);
use BuiltNorth\WPUtility\Setup\ImageSetup;
ImageSetup::setup();
add_filter('wp_utility_image_sizes', function($sizes) {
$sizes['banner'] = [1920, 600, true];
$sizes['thumbnail_large'] = [400, 400, true];
return $sizes;
});
add_filter('wp_utility_image_size_names', function($names) {
$names['banner'] = __('Banner Image');
$names['thumbnail_large'] = __('Large Thumbnail');
return $names;
});
// camelCase
Component::accessibleCard();
Utility::getTitle();
Helper::escapeSvg();
// PascalCase (PHP is case-insensitive for methods)
Component::AccessibleCard();
Utility::GetTitle();
Helper::EscapeSvg();
// snake_case (via magic methods)
Component::accessible_card();
Utility::get_title();
Helper::escape_svg();