Loading...

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 located in functions.php, inc/template-tags.php and woocommerce/woocommerce-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 functions.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

  • Breadcrumb
  • Widgets
  • Pagination
  • Nav-walker
  • Styles & scripts

template-tags.php

  • Categories badge
  • Tags badge
  • Featured Image
  • Author
  • Date
  • Comments count
  • Internet Explorer alert

woocommerce-functions.php

  • WooCommerce breadcrumb
  • 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.
  • Optional telephone in checkout.

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.

Cookies help us deliver our services. By using our services, you agree to our use of cookies. More Information