Loading...
Bootscore 6.4 is here! Learn more

Functions

| 2 Comments on Functions

Almost all functions are pluggable and can be overwritten in the child-theme.

Pluggable functions are wrapped in if (!function_exists('function_name')) :endif; and fetched in functions.php and woocommerce/wc-functions.php.

if (!function_exists('function_name')) :

  // Function

endif;

Functions can be overridden by copying the function between the if and endif to the child’s functions.php.

Example: Changing the breadcrumb

There is no need to edit the breadcrumb or other functions this way, as filters and actions are available for more flexible customization. This is just an example of how pluggable functions work.

/**
 * Breadcrumb
 */
function the_breadcrumb() {

  if (!is_home()) {
    echo '<nav aria-label="breadcrumb" class="mb-4 mt-2">';
    echo '<ol class="breadcrumb mb-0">';
    echo '<li class="breadcrumb-item"><a href="' . home_url() . '">' . 'Home' . '</a></li>';
    // display parent category names with links
    if (is_category() || is_single()) {
      $cat_IDs = wp_get_post_categories(get_the_ID());
      foreach ($cat_IDs as $cat_ID) {
        $cat = get_category($cat_ID);
        echo '<li class="breadcrumb-item"><a href="' . get_term_link($cat->term_id) . '">' . $cat->name . '</a></li>';
      }
    }
    // display current page name
    if (is_page() || is_single()) {
      echo '<li class="breadcrumb-item active" aria-current="page">' . get_the_title() . '</li>';
    }
    echo '</ol>';
    echo '</nav>';
  }
}

Useful functions

  • inc/breadcrumb.php – Breadcrumb
  • inc/widgets.php – Widgets
  • inc/pagination.php – Pagination
  • inc/template-tags.php – Categories badge, tags badge, featured image, author, date, comments count
  • woocommerce/inc/breadcrumb.php – WooCommerce breadcrumb
  • woocommerce/inc/wc-mini-cart.php – Cart content in navbar mini-cart. Note that this function is AJAX loaded. When doing changes there, you must add or remove something in your cart. Reloading the page has no effect.