Loading...

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;

Example: Pagination / amount of posts

The amount of posts, products or custom post types is limited to 24 items per page in inc/loop.php. If there are more than 24 items, pagination buttons are displayed.

// Amount of posts/products in category
if (!function_exists('wpsites_query')) :

  function wpsites_query($query) {
    if ($query->is_archive() && $query->is_main_query() && !is_admin()) {
      $query->set('posts_per_page', 24);
    }
  }
  add_action('pre_get_posts', 'wpsites_query');

endif;
// Amount of posts/products in category END

Copy the function between the if and endif to your child-theme’s functions.php and change number from 24 to 64.

function wpsites_query($query) {
  if ($query->is_archive() && $query->is_main_query() && !is_admin()) {
    $query->set('posts_per_page', 64);
  }
}
add_action('pre_get_posts', 'wpsites_query');

Now 64 posts are displayed.

Useful functions

functions.php

  • inc/breadcrumb.php – Breadcrumb
  • inc/widgets.php – Widgets
  • inc/pagination.php – Pagination
  • inc/loop.php – Amount of posts/products
  • inc/columns.php – Main-col/sidebar width and breakpoints
  • inc/container.php – Containers
  • inc/template-tags.php – Categories badge, tags badge, featured image, author, date, comments count

wc-functions.php

  • 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.
  • woocommerce/wc-functions.php – AJAX cart script

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