/**
* indofact functions and definitions
*
* @package indofact
*/
/**
* Define theme constants
*/
$tmc_theme = wp_get_theme();
if ( $tmc_theme->exists() ) {
define( 'TMC_THEME_NAME', $tmc_theme->get( 'Name' ) );
define( 'TMC_THEME_VERSION', $tmc_theme->get( 'Version' ) );
}
/**
* Set the content width based on the theme's design and stylesheet.
*/
if ( ! isset( $content_width ) ) {
$content_width = 1170;
}
add_action( 'after_setup_theme', 'tmc_theme_setup' );
if ( ! function_exists( 'tmc_theme_setup' ) ) {
function tmc_theme_setup()
{
/*
* Make theme available for translation.
* Translations can be filed in the /languages/ directory.
* If you're building a theme based on industrial, use a find and replace
* to change 'indofact' to the name of your theme in all the template files
*/
load_theme_textdomain( 'indofact', get_template_directory() . '/languages' );
// Add default posts and comments RSS feed links to head.
add_theme_support( 'automatic-feed-links' );
/*
* Let WordPress manage the document title.
* By adding theme support, we declare that this theme does not use a
* hard-coded
tag in the document head, and expect WordPress to
* provide it for us.
*/
add_theme_support( 'title-tag' );
if ( ! get_post_meta( get_the_ID(), 'disable_tags', true ) ) {
the_tags( '
', ' ', '
' );
}
//Image Croped for Latest News
add_image_size( 'tmc-image-370x253-croped', 370, 253, true );
//Image Croped for projects
add_image_size( 'tmc-image-457x485-croped', 457, 485, true );
//Image Croped for portfolio two
add_image_size( 'tmc-image-555x429-croped', 555, 429, true );
//Image Croped for portfolio three
add_image_size( 'tmc-image-360x278-croped', 360, 278, true );
//Image Croped for portfolio four
add_image_size( 'tmc-image-263x203-croped', 263, 203, true );
//Image Croped for portfolio five
add_image_size( 'tmc-image-240x185-croped', 240, 185, true );
add_theme_support( 'post-thumbnails' );
add_theme_support( 'title-tag' );
add_theme_support( 'automatic-feed-links' );
add_theme_support( 'tmc' );
add_theme_support( 'html5', array(
'search-form',
'comment-form',
'comment-list',
'gallery',
'caption'
) );
/*
* Enable support for custome header and background for the images.
*/
add_theme_support( 'custom-header' );
add_theme_support( 'custom-background' ) ;
// This theme styles the visual editor to resemble the theme style.
/*
* Gutenberg Compatible
*/
add_theme_support( 'align-wide' );
add_theme_support( 'wp-block-styles' );
add_theme_support( 'editor-styles' );
//WooCommerce Theme Support
add_theme_support('woocommerce');
if ( class_exists('Woocommerce') )
{
global $tmc_option;
$tmc_option = get_option('tmc_option');
// Increase Number of Related Products to 4
if (!function_exists('woocommerce_related_output'))
{
function woocommerce_related_output()
{
global $product, $orderby, $related;
$args = array(
'posts_per_page' => '4',
'columns' => '4',
);
return $args;
}
}
add_filter( 'woocommerce_output_related_products_args', 'woocommerce_related_output' );
// Change products per page
if(!empty($tmc_option['text_shopitems']))
{
add_filter( 'loop_shop_per_page', 'new_loop_shop_per_page', 20 );
function new_loop_shop_per_page( $cols ) {
global $tmc_option;
// $cols contains the current number of products per page based on the value stored on Options -> Reading
// Return the number of products you wanna show per page.
$cols = $tmc_option['text_shopitems'];
return $cols;
}
}
// Toggle Sort by Function
if(isset($tmc_option["switch_shopsorting"]) && $tmc_option["switch_shopsorting"] == 0)
{
remove_action( 'woocommerce_before_shop_loop', 'woocommerce_catalog_ordering', 30 );
}
// Toggle Result Count
if(isset($tmc_option["switch_shopresultcount"]) && $tmc_option["switch_shopresultcount"] == 0)
{
remove_action( 'woocommerce_before_shop_loop', 'woocommerce_result_count', 20 );
}
// Toggle Upsell Products
if(isset($tmc_option["switch_shopupsells"]) && $tmc_option["switch_shopupsells"] == 0)
{
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_upsell_display', 15);
}
// Toggle Related Products
if(isset($tmc_option["switch_shoprelatedproducts"]) && $tmc_option["switch_shoprelatedproducts"] == 0)
{
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20);
}
// Toggle Add to Cart Button
if(isset($tmc_option["switch_addtocart"]) && $tmc_option["switch_addtocart"] == 0)
{
add_action('init','woocommerce_remove_loop_button');
}
// Remove Cart Cross Sells
remove_action( 'woocommerce_cart_collaterals', 'woocommerce_cross_sell_display' );
// Remove Add to Cart Button
function woocommerce_remove_loop_button()
{
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
}
} // end if woocommerce class exists
add_editor_style( 'assets/css/editor-style.css' );
register_nav_menus(
array(
'tmc-primary' => esc_html__( 'Primary','indofact' ),
'tmc-footer-one' => esc_html__( 'Footer One','indofact' ),
'tmc-footer-two' => esc_html__( 'Footer Two','indofact' ),
'tmc-service' => esc_html__( 'Service','indofact' )
)
);
}
}
function tmc_read_more_link() {
return ''.esc_html__('Read more','indofact').'';
}
add_filter( 'the_content_more_link', 'tmc_read_more_link' );
//Default Home on breadcumb
add_filter('bcn_breadcrumb_title', function($title, $type, $id) {
if ($type[0] === 'home') {
$title = get_the_title(get_option('page_on_front'));
}
return $title;
}, 42, 3);
/************************************************************************
* Set Inner header and footer background image/color.
*************************************************************************/
function backgroundStyle( $key ){
global $tmc_option;
$inner_header_style = array();
if ( isset($tmc_option[''.esc_attr($key).'']) && !empty($tmc_option[''.esc_attr($key).'']['background-image']))
{
$inner_header_style[] = 'background-image: url('.$tmc_option[''.esc_attr($key).'']['background-image'].');';
}
if ( isset($tmc_option[''.esc_attr($key).'']) && !empty($tmc_option[''.esc_attr($key).'']['background-color']))
{
$inner_header_style[] = 'background-color: '.$tmc_option[''.esc_attr($key).'']['background-color'].';';
}
if ( isset($tmc_option[''.esc_attr($key).'']) && !empty($tmc_option[''.esc_attr($key).'']['background-repeat']))
{
$inner_header_style[] = 'background-repeat: '.$tmc_option[''.esc_attr($key).'']['background-repeat'].';';
}
if ( isset($tmc_option[''.esc_attr($key).'']) && !empty($tmc_option[''.esc_attr($key).'']['background-size']) )
{
$inner_header_style[] = 'background-size: '.$tmc_option[''.esc_attr($key).'']['background-size'].';';
}
if ( isset($tmc_option[''.esc_attr($key).'']) && !empty($tmc_option[''.esc_attr($key).'']['background-position']))
{
$inner_header_style[] = 'background-position: '.$tmc_option[''.esc_attr($key).'']['background-position'].';';
}
if ( isset($tmc_option[''.esc_attr($key).'']) && !empty($tmc_option[''.esc_attr($key).'']['background-attachment']) )
{
$inner_header_style[] = 'background-attachment: '.$tmc_option[''.esc_attr($key).'']['background-attachment'].';';
}
return $inner_header_style;
}
/************************************************************************
* Theme Meta box value.
*************************************************************************/
function metaBox()
{
$metaData = array();
$metaData['hide-title'] = get_post_meta( get_the_ID(), 'page-hide-title', true );
$metaData['hide-breadcrumb'] = get_post_meta( get_the_ID(), 'page-hide-breadcrumb', true );
$metaData['header-title'] = get_post_meta( get_the_ID(), 'page-header-title', true );
$metaData['title-color'] = get_post_meta( get_the_ID(), 'page-title-color', true );
$metaData['title-alignment'] = get_post_meta( get_the_ID(), 'page-title-alignment', true );
$metaData['title-padding-top'] = get_post_meta( get_the_ID(), 'page-title-padding-top', true );
$metaData['title-padding-bottom'] = get_post_meta( get_the_ID(), 'page-title-padding-bottom', true );
$metaData['header-height'] = get_post_meta( get_the_ID(), 'page-header-height', true );
$metaData['hide-background'] = get_post_meta( get_the_ID(), 'page-hide-background', true );
$metaData['background-color'] = get_post_meta( get_the_ID(), 'page-background-color', true );
$metaData['header-image'] = get_post_meta( get_the_ID(), 'page-header-image', true );
$metaData['image-repeat'] = get_post_meta( get_the_ID(), 'page-header-image-repeat', true );
$metaData['image-size'] = get_post_meta( get_the_ID(), 'page-header-image-size', true );
$metaData['image-attachment'] = get_post_meta( get_the_ID(), 'page-header-image-attachment', true );
$metaData['image-position'] = get_post_meta( get_the_ID(), 'page-header-image-position', true );
$metaData['content-padding-top'] = get_post_meta( get_the_ID(), 'page-content-padding-top', true );
$metaData['content-padding-bottom'] = get_post_meta( get_the_ID(), 'page-content-padding-bottom', true );
$metaData['hide-footer'] = get_post_meta( get_the_ID(), 'page-hide-footer', true );
$metaData['footer-background-color'] = get_post_meta( get_the_ID(), 'page-footer-background-color', true );
$metaData['footer-background-image'] = get_post_meta( get_the_ID(), 'page-footer-image', true );
$metaData['footer-image-repeat'] = get_post_meta( get_the_ID(), 'page-footer-image-repeat', true );
$metaData['footer-image-size'] = get_post_meta( get_the_ID(), 'page-footer-image-size', true );
$metaData['footer-image-attachment'] = get_post_meta( get_the_ID(), 'page-footer-image-attachment', true );
$metaData['footer-image-position'] = get_post_meta( get_the_ID(), 'page-footer-image-position', true );
$metaData['footer-title-color'] = get_post_meta( get_the_ID(), 'page-footer-title-color', true );
$metaData['footer-text-color'] = get_post_meta( get_the_ID(), 'page-footer-text-color', true );
$metaData['hide-copyright'] = get_post_meta( get_the_ID(), 'page-hide-copyright', true );
return $metaData;
}
/************************************************************************
* Theme Meta box post type.
*************************************************************************/
function postType(){
$metaData = '';
$metaData = metaBox();
return $metaData;
}
if ( ! function_exists( 'tmc_register_default_sidebars' ) ) {
function tmc_register_default_sidebars() {
//Right Sidebar
register_sidebar( array(
'id' => 'tmc-right-sidebar',
'name' => esc_html__( 'Right Sidebar','indofact' ),
'description' => esc_html__( 'Add widgets here to appear in Right Sidebar','indofact'),
'before_widget' => '
',
'after_widget' => '
',
'before_title' => '
',
'after_title' => '
',
) );
//Left Sidebar
register_sidebar( array(
'id' => 'tmc-left-sidebar',
'name' => esc_html__( 'Left Sidebar','indofact' ),
'description' => esc_html__( 'Add widgets here to appear in Left Sidebar','indofact'),
'before_widget' => '