Loading...
Bootscore v6 is here! Learn more

Documentation Theme

Functions

Almost all functions are pluggable and can be overridden 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

/**
 * 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.

2 Comments on “Functions”

  • Ersin Koray Gonce

    says:

    Hello there;
    How do I override the inc/template-tags.php file. for use in child theme. Or should I change it through the parent theme?

    I copied the inc folder to the child theme but it didn’t work. how do i do this.

    • Basti

      says:

      Hi Ersin,

      you cannot override the whole file in child, but you can override all functions in it. Copy function between the if and endif statement like described in the article above to your child-theme functions.php and edit there.

      BTW, all changes you do in the parent theme will be lost by the next update. So, better not to do any changes there.

Comments are closed.

To top