Template Helpers

PHP helper functions for theme development.

PHP Helper Functions

WPDocs provides global PHP functions for use in theme templates and custom code.

wpdocs_get_option($key, $default)

Retrieve a plugin setting value:

$color = wpdocs_get_option('primary_color', '#3B82F6');
$logo  = wpdocs_get_option('logo_url', '');
$logo_dark = wpdocs_get_option('logo_dark_url', '');

wpdocs_plugin_active()

Check if the WPDocs Core plugin is loaded:

if (wpdocs_plugin_active()) {
    // Safe to use plugin functions
}

wpdocs_is_premium()

Check if a valid premium license is active:

if (wpdocs_is_premium()) {
    // Show premium-only feature
}

wpdocs_get_sidebar_sections($version)

Get all sections ordered for the sidebar:

$sections = wpdocs_get_sidebar_sections();

// Filter by version
$sections = wpdocs_get_sidebar_sections('v2-0');

wpdocs_get_docs_by_section($section_id, $version)

Get doc pages within a section:

$docs = wpdocs_get_docs_by_section(42);

// With version filter
$docs = wpdocs_get_docs_by_section(42, 'v2-0');

wpdocs_get_first_doc()

Get the first doc page (for landing redirects):

$first = wpdocs_get_first_doc();
if ($first) {
    wp_redirect(get_permalink($first->ID));
    exit;
}

wpdocs_get_prev_next($post_id)

Get adjacent doc IDs in sidebar order:

$nav = wpdocs_get_prev_next(get_the_ID());
// ['prev' => 41, 'next' => 43]

WPDocs_Icons::get($slug)

echo WPDocs_Icons::get('rocket-launch');
// Returns SVG string