tag in the document head, and expect WordPress to
* provide it for us.
*/
add_theme_support( 'title-tag' );
/*
* Enable support for Post Thumbnails on posts and pages.
*
* @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/
*/
add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 150, 150, true );
add_image_size( 'one-pageily-related', 200, 125, true ); //related
// This theme uses wp_nav_menu() in one location.
register_nav_menus( array(
'primary' => esc_html__( 'Primary', 'one-pageily' ),
) );
/*
* Switch default core markup for search form, comment form, and comments
* to output valid HTML5.
*/
add_theme_support( 'html5', array(
'comment-form',
'comment-list',
'gallery',
'caption',
) );
if ( one_pageily_is_wc_active() ) {
add_theme_support( 'woocommerce' );
}
// Set up the WordPress core custom background feature.
add_theme_support( 'custom-background', apply_filters( 'one_pageily_custom_background_args', array(
'default-color' => '#eee',
'default-image' => '',
) ) );
}
endif;
add_action( 'after_setup_theme', 'one_pageily_setup' );
function one_pageily_content_width() {
$GLOBALS['content_width'] = apply_filters( 'one_pageily_content_width', 678 );
}
add_action( 'after_setup_theme', 'one_pageily_content_width', 0 );
/**
* Register widget area.
*
* @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
*/
function one_pageily_widgets_init() {
register_sidebar( array(
'name' => esc_html__( 'Sidebar', 'one-pageily' ),
'id' => 'sidebar',
'description' => '',
'before_widget' => '
',
'after_widget' => '
',
'before_title' => '',
) );
// First Top Widget
register_sidebar( array(
'name' => __( 'Top Widget 1', 'one-pageily' ),
'description' => __( 'First Top Widget Column', 'one-pageily' ),
'id' => 'top-widget-first',
'before_widget' => '',
'after_widget' => '
',
'before_title' => '',
) );
// Second Top Widget
register_sidebar( array(
'name' => __( 'Top Widget 2', 'one-pageily' ),
'description' => __( 'Second Top Widget Column', 'one-pageily' ),
'id' => 'top-widget-second',
'before_widget' => '',
'after_widget' => '
',
'before_title' => '',
) );
// Third Top Widget
register_sidebar( array(
'name' => __( 'Top Widget 3', 'one-pageily' ),
'description' => __( 'Third Top Widget Column', 'one-pageily' ),
'id' => 'top-widget-third',
'before_widget' => '',
'after_widget' => '
',
'before_title' => '',
) );
// First Footer
register_sidebar( array(
'name' => __( 'Footer 1', 'one-pageily' ),
'description' => __( 'First footer column', 'one-pageily' ),
'id' => 'footer-first',
'before_widget' => '',
'after_widget' => '
',
'before_title' => '',
) );
// Second Footer
register_sidebar( array(
'name' => __( 'Footer 2', 'one-pageily' ),
'description' => __( 'Second footer column', 'one-pageily' ),
'id' => 'footer-second',
'before_widget' => '',
'after_widget' => '
',
'before_title' => '',
) );
// Third Footer
register_sidebar( array(
'name' => __( 'Footer 3', 'one-pageily' ),
'description' => __( 'Third footer column', 'one-pageily' ),
'id' => 'footer-third',
'before_widget' => '',
'after_widget' => '
',
'before_title' => '',
) );
if ( one_pageily_is_wc_active() ) {
// Register WooCommerce Shop and Single Product Sidebar
register_sidebar( array(
'name' => __('Shop Page Sidebar', 'one-pageily' ),
'description' => __( 'Appears on Shop main page and product archive pages.', 'one-pageily' ),
'id' => 'shop-sidebar',
'before_widget' => '',
'after_widget' => '
',
'before_title' => '',
) );
register_sidebar( array(
'name' => __('Single Product Sidebar', 'one-pageily' ),
'description' => __( 'Appears on single product pages.', 'one-pageily' ),
'id' => 'product-sidebar',
'before_widget' => '',
'after_widget' => '
',
'before_title' => '',
) );
}
}
add_action( 'widgets_init', 'one_pageily_widgets_init' );
function one_pageily_custom_sidebar() {
// Default sidebar.
$sidebar = 'sidebar';
// Woocommerce.
if ( one_pageily_is_wc_active() ) {
if ( is_shop() || is_product_category() ) {
$sidebar = 'shop-sidebar';
}
if ( is_product() ) {
$sidebar = 'product-sidebar';
}
}
return $sidebar;
}
/**
* Enqueue scripts and styles.
*/
function one_pageily_scripts() {
wp_enqueue_style( 'one-pageily-style', get_stylesheet_uri() );
$handle = 'one-pageily-style';
// WooCommerce
if ( one_pageily_is_wc_active() ) {
if ( is_woocommerce() || is_cart() || is_checkout() ) {
wp_enqueue_style( 'woocommerce', get_template_directory_uri() . '/css/woocommerce2.css' );
$handle = 'woocommerce';
}
}
wp_enqueue_script( 'one-pageily-customscripts', get_template_directory_uri() . '/js/customscripts.js',array('jquery'),'',true);
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
}
add_action( 'wp_enqueue_scripts', 'one_pageily_scripts' );
/**
* Implement the Custom Header feature.
*/
require get_template_directory() . '/inc/custom-header.php';
/**
* Custom template tags for this theme.
*/
require get_template_directory() . '/inc/template-tags.php';
/**
* Custom functions that act independently of the theme templates.
*/
require get_template_directory() . '/inc/extras.php';
/**
* Customizer additions.
*/
require get_template_directory() . '/inc/customizer.php';
/**
* Load Jetpack compatibility file.
*/
require get_template_directory() . '/inc/jetpack.php';
/**
* Copyrights
*/
if ( ! function_exists( 'one_pageily_copyrights_credit' ) ) {
function one_pageily_copyrights_credit() {
global $onepageily_options
?>
id="li-comment-">
=$limit) {
array_pop($excerpt);
$excerpt = implode(" ",$excerpt);
} else {
$excerpt = implode(" ",$excerpt);
}
$excerpt = preg_replace('`[[^]]*]`','',$excerpt);
return $excerpt;
}
/**
* Shorthand function to check for more tag in post.
*
* @return bool|int
*/
function one_pageily_post_has_moretag() {
return strpos( get_the_content(), '' );
}
if ( ! function_exists( 'one_pageily_readmore' ) ) {
/**
* Display a "read more" link.
*/
function one_pageily_readmore() {
?>
'.esc_html(sprintf( __( "Home", 'one-pageily' )));
echo '';
if (is_single()) {
$categories = get_the_category();
if ( $categories ) {
$level = 0;
$hierarchy_arr = array();
foreach ( $categories as $cat ) {
$anc = get_ancestors( $cat->term_id, 'category' );
$count_anc = count( $anc );
if ( 0 < $count_anc && $level < $count_anc ) {
$level = $count_anc;
$hierarchy_arr = array_reverse( $anc );
array_push( $hierarchy_arr, $cat->term_id );
}
}
if ( empty( $hierarchy_arr ) ) {
$category = $categories[0];
echo ''.esc_html( $category->name ).'';
} else {
foreach ( $hierarchy_arr as $cat_id ) {
$category = get_term_by( 'id', $cat_id, 'category' );
echo ''.esc_html( $category->name ).'';
}
}
}
echo "";
the_title();
echo "";
} elseif (is_page()) {
$parent_id = wp_get_post_parent_id( get_the_ID() );
if ( $parent_id ) {
$breadcrumbs = array();
while ( $parent_id ) {
$page = get_page( $parent_id );
$breadcrumbs[] = ''.esc_html( get_the_title($page->ID) ). '';
$parent_id = $page->post_parent;
}
$breadcrumbs = array_reverse( $breadcrumbs );
foreach ( $breadcrumbs as $crumb ) { echo $crumb; }
}
echo "";
the_title();
echo "";
} elseif (is_category()) {
global $wp_query;
$cat_obj = $wp_query->get_queried_object();
$this_cat_id = $cat_obj->term_id;
$hierarchy_arr = get_ancestors( $this_cat_id, 'category' );
if ( $hierarchy_arr ) {
$hierarchy_arr = array_reverse( $hierarchy_arr );
foreach ( $hierarchy_arr as $cat_id ) {
$category = get_term_by( 'id', $cat_id, 'category' );
echo ''.esc_html( $category->name ).'';
}
}
echo "";
single_cat_title();
echo "";
} elseif (is_author()) {
echo "";
if(get_query_var('author_name')) :
$curauth = get_user_by('slug', get_query_var('author_name'));
else :
$curauth = get_userdata(get_query_var('author'));
endif;
echo esc_html( $curauth->nickname );
echo "";
} elseif (is_search()) {
echo "";
the_search_query();
echo "";
} elseif (is_tag()) {
echo "";
single_tag_title();
echo "";
}
}
}
/*
* Google Fonts
*/
function one_pageily_fonts_url() {
$fonts_url = '';
/* Translators: If there are characters in your language that are not
* supported by Monda, translate this to 'off'. Do not translate
* into your own language.
*/
$monda = _x( 'on', 'Monda font: on or off', 'one-pageily' );
if ( 'off' !== $monda ) {
$font_families = array();
if ( 'off' !== $monda ) {
$font_families[] = urldecode('Roboto:300,400,500,700,900');
}
$query_args = array(
'family' => urlencode( implode( '|', $font_families ) ),
//'subset' => urlencode( 'latin,latin-ext' ),
);
$fonts_url = add_query_arg( $query_args, '//fonts.googleapis.com/css' );
}
return $fonts_url;
}
function one_pageily_scripts_styles() {
wp_enqueue_style( 'theme-slug-fonts', one_pageily_fonts_url(), array(), null );
}
add_action( 'wp_enqueue_scripts', 'one_pageily_scripts_styles' );
/**
* WP Mega Menu Plugin Support
*/
function one_pageily_megamenu_parent_element( $selector ) {
return '.primary-navigation .container';
}
add_filter( 'wpmm_container_selector', 'one_pageily_megamenu_parent_element' );
/**
* Determines whether the WooCommerce plugin is active or not.
* @return bool
*/
function one_pageily_is_wc_active() {
if ( is_multisite() ) {
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
return is_plugin_active( 'woocommerce/woocommerce.php' );
} else {
return in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) );
}
}
/**
* WooCommerce
*/
if ( one_pageily_is_wc_active() ) {
if ( !function_exists( 'onepageily_loop_columns' )) {
/**
* Change number or products per row to 3
*
* @return int
*/
function onepageily_loop_columns() {
return 3; // 3 products per row
}
}
add_filter( 'loop_shop_columns', 'onepageily_loop_columns' );
/**
* Redefine woocommerce_output_related_products()
*/
function woocommerce_output_related_products() {
$args = array(
'posts_per_page' => 3,
'columns' => 3,
);
woocommerce_related_products($args); // Display 3 products in rows of 1
}
global $pagenow;
if ( is_admin() && isset( $_GET['activated'] ) && $pagenow == 'themes.php' ) {
/**
* Define WooCommerce image sizes.
*/
function one_pageily_woocommerce_image_dimensions() {
$catalog = array(
'width' => '210', // px
'height' => '155', // px
'crop' => 1 // true
);
$single = array(
'width' => '326', // px
'height' => '444', // px
'crop' => 1 // true
);
$thumbnail = array(
'width' => '74', // px
'height' => '74', // px
'crop' => 0 // false
);
// Image sizes
update_option( 'shop_catalog_image_size', $catalog ); // Product category thumbs
update_option( 'shop_single_image_size', $single ); // Single product image
update_option( 'shop_thumbnail_image_size', $thumbnail ); // Image gallery thumbs
}
add_action( 'init', 'one_pageily_woocommerce_image_dimensions', 1 );
}
/**
* Change the number of product thumbnails to show per row to 4.
*
* @return int
*/
function one_pageily_woocommerce_thumb_cols() {
return 4; // .last class applied to every 4th thumbnail
}
add_filter( 'woocommerce_product_thumbnails_columns', 'one_pageily_woocommerce_thumb_cols' );
/**
* Ensure cart contents update when products are added to the cart via AJAX.
*
* @param $fragments
*
* @return mixed
*/
function one_pageily_header_add_to_cart_fragment( $fragments ) {
global $woocommerce;
ob_start(); ?>
cart->cart_contents_count, 'one-pageily' ), $woocommerce->cart->cart_contents_count );?> - cart->get_cart_total(); ?>