File: /home/dreamlan/public_html/wp-content/themes/DreamLandNepal/functions.php
<?php
/***** Fetch Options *****/
$options = get_option('mh_options');
/***** Custom Hooks *****/
function mh_html_class() {
do_action('mh_html_class');
}
function mh_html_tag() {
do_action('mh_html_tag');
}
function mh_body_id() {
do_action('mh_body_id');
}
function mh_container_class() {
do_action('mh_container_class');
}
function mh_before_header() {
do_action('mh_before_header');
}
function mh_after_header() {
do_action('mh_after_header');
}
function mh_content_class() {
do_action('mh_content_class');
}
function mh_before_page_content() {
do_action('mh_before_page_content');
}
function mh_before_post_content() {
do_action('mh_before_post_content');
}
function mh_post_header() {
do_action('mh_post_header');
}
function mh_post_content() {
do_action('mh_post_content');
}
function mh_loop_content() {
do_action('mh_loop_content');
}
function mh_after_post_content() {
do_action('mh_after_post_content');
}
function mh_sb_class() {
do_action('mh_sb_class');
}
/***** Enable Shortcodes inside Widgets *****/
add_filter('widget_text', 'do_shortcode');
/***** Theme Setup *****/
add_action('after_setup_theme', 'mh_themes_setup');
add_action('wp_enqueue_scripts', 'mh_scripts');
add_action('admin_enqueue_scripts', 'mh_admin_scripts');
add_action('widgets_init', 'mh_widgets_init');
function mh_themes_setup() {
global $content_width;
if (!isset($content_width)) {
$content_width = 620;
}
$header = array(
'default-image' => get_template_directory_uri() . '/images/logo.png',
'width' => 300,
'height' => 100,
'flex-width' => true,
'flex-height' => true,
'header-text' => false
);
add_theme_support('custom-header', $header);
load_theme_textdomain('mh', get_template_directory() . '/languages');
add_theme_support('automatic-feed-links');
add_theme_support('custom-background');
add_theme_support('post-thumbnails');
add_image_size('slider', 940, 400, true);
add_image_size('content', 620, 264, true);
add_image_size('spotlight', 580, 326, true);
add_image_size('loop', 174, 131, true);
add_image_size('carousel', 174, 98, true);
add_image_size('cp_breaking', 1100, 500, true);
add_image_size('nip_small', 300, true);
add_image_size('breaking-news', 1120, 600, $crop);
add_image_size('sidebar-img', 350, true);
add_image_size('cp_large', 350, 263, true);
add_image_size('interview', 200, 200, array( 'left', 'top' ));
add_image_size('cp_small', 60, 60, true);
add_image_size('nip_small', 360, true);
add_image_size('special_small', 100, 90, true);
add_image_size('bull_small', 80, 80, true);
add_editor_style();
register_nav_menus(array(
'header_nav' => __('Header Navigation', 'mh'),
'main_nav' => __('Main Navigation', 'mh'),
'footer_nav' => __('Footer Navigation', 'mh')
));
}
/***** Load JavaScript *****/
if (!function_exists('mh_scripts')) {
function mh_scripts() {
wp_deregister_script('jquery');
wp_register_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js');
wp_enqueue_script('jquery');
wp_enqueue_script('jquery migrate', 'http://code.jquery.com/jquery-migrate-1.2.1.js');
wp_enqueue_script('scripts', get_template_directory_uri() . '/js/scripts.js', array('jquery'));
if (!is_admin()) {
if (is_singular() && comments_open() && (get_option('thread_comments') == 1))
wp_enqueue_script('comment-reply');
}
}
}
if (!function_exists('mh_admin_scripts')) {
function mh_admin_scripts($hook) {
wp_enqueue_style('mh-admin', get_template_directory_uri() . '/admin/admin.css');
if ($hook != 'post.php' && $hook != 'post-new.php') {
return;
}
wp_enqueue_script('simplyCountable', get_template_directory_uri() . '/js/jquery.simplyCountable.js');
wp_enqueue_script('custom-admin-js', get_template_directory_uri() . '/js/custom_admin.js');
}
}
/***** Register Widget Areas / Sidebars *****/
if (!function_exists('mh_widgets_init')) {
function mh_widgets_init() {
global $options;
isset($options['2nd_sidebar']) && $options['2nd_sidebar'] ? $two_sidebars = true : $two_sidebars = false;
isset($options['site_width']) && $options['site_width'] == 'large' || isset($options['2nd_sidebar']) && $options['2nd_sidebar'] ? $large_site = true : $large_site = false;
register_sidebar(array('name' => __('Header', 'mh'), 'id' => 'header', 'description' => __('Widget area on top of the site', 'mh'), 'before_widget' => '<div class="sb-widget">', 'after_widget' => '</div>', 'before_title' => '<h4 class="widget-title">', 'after_title' => '</h4>'));
register_sidebar(array('name' => __('Sidebar', 'mh'), 'id' => 'sidebar', 'description' => __('Widget area (sidebar left/right) on single posts, pages and archives', 'mh'), 'before_widget' => '<div class="sb-widget">', 'after_widget' => '</div>', 'before_title' => '<h4 class="widget-title">', 'after_title' => '</h4>'));
if ($two_sidebars) {
register_sidebar(array('name' => __('Sidebar 2', 'mh'), 'id' => 'sidebar-2', 'description' => __('Second sidebar on single posts, pages and archives', 'mh'), 'before_widget' => '<div class="sb-widget">', 'after_widget' => '</div>', 'before_title' => '<h4 class="widget-title">', 'after_title' => '</h4>'));
}
register_sidebar(array('name' => __('Home 1', 'mh'), 'id' => 'home-1', 'description' => __('Widget area on homepage', 'mh'), 'before_widget' => '<div class="sb-widget home-1">', 'after_widget' => '</div>', 'before_title' => '<h4 class="widget-title">', 'after_title' => '</h4>'));
register_sidebar(array('name' => __('Home 2', 'mh'), 'id' => 'home-2', 'description' => __('Widget area on homepage', 'mh'), 'before_widget' => '<div class="sb-widget home-2">', 'after_widget' => '</div>', 'before_title' => '<h4 class="widget-title">', 'after_title' => '</h4>'));
register_sidebar(array('name' => __('Home 3', 'mh'), 'id' => 'home-3', 'description' => __('Widget area on homepage', 'mh'), 'before_widget' => '<div class="sb-widget home-3">', 'after_widget' => '</div>', 'before_title' => '<h4 class="widget-title">', 'after_title' => '</h4>'));
register_sidebar(array('name' => __('Home 4', 'mh'), 'id' => 'home-4', 'description' => __('Widget area on homepage', 'mh'), 'before_widget' => '<div class="sb-widget home-4">', 'after_widget' => '</div>', 'before_title' => '<h4 class="widget-title">', 'after_title' => '</h4>'));
register_sidebar(array('name' => __('Home 5', 'mh'), 'id' => 'home-5', 'description' => __('Widget area on homepage', 'mh'), 'before_widget' => '<div class="sb-widget home-5">', 'after_widget' => '</div>', 'before_title' => '<h4 class="widget-title">', 'after_title' => '</h4>'));
register_sidebar(array('name' => __('Home 6', 'mh'), 'id' => 'home-6', 'description' => __('Widget area on homepage', 'mh'), 'before_widget' => '<div class="sb-widget home-6">', 'after_widget' => '</div>', 'before_title' => '<h4 class="widget-title">', 'after_title' => '</h4>'));
register_sidebar(array('name' => __('Home 7', 'mh'), 'id' => 'home-7', 'description' => __('Widget area on homepage', 'mh'), 'before_widget' => '<div class="sb-widget home-7">', 'after_widget' => '</div>', 'before_title' => '<h4 class="widget-title">', 'after_title' => '</h4>'));
register_sidebar(array('name' => __('Home 8', 'mh'), 'id' => 'home-8', 'description' => __('Widget area on homepage', 'mh'), 'before_widget' => '<div class="sb-widget home-8">', 'after_widget' => '</div>', 'before_title' => '<h4 class="widget-title">', 'after_title' => '</h4>'));
register_sidebar(array('name' => __('Home 9', 'mh'), 'id' => 'home-9', 'description' => __('Widget area on homepage', 'mh'), 'before_widget' => '<div class="sb-widget home-9">', 'after_widget' => '</div>', 'before_title' => '<h4 class="widget-title">', 'after_title' => '</h4>'));
register_sidebar(array('name' => __('Home 10', 'mh'), 'id' => 'home-10', 'description' => __('Widget area on homepage', 'mh'), 'before_widget' => '<div class="sb-widget home-10">', 'after_widget' => '</div>', 'before_title' => '<h4 class="widget-title">', 'after_title' => '</h4>'));
register_sidebar(array('name' => __('Home 11', 'mh'), 'id' => 'home-11', 'description' => __('Widget area on homepage', 'mh'), 'before_widget' => '<div class="sb-widget home-11">', 'after_widget' => '</div>', 'before_title' => '<h4 class="widget-title">', 'after_title' => '</h4>'));
if ($large_site) {
register_sidebar(array('name' => __('Home 12', 'mh'), 'id' => 'home-12', 'description' => __('Sidebar on homepage', 'mh'), 'before_widget' => '<div class="sb-widget home-12">', 'after_widget' => '</div>', 'before_title' => '<h4 class="widget-title">', 'after_title' => '</h4>'));
}
register_sidebar(array('name' => __('Posts 1', 'mh'), 'id' => 'posts-1', 'description' => __('Widget area above single post content', 'mh'), 'before_widget' => '<div class="sb-widget posts-1">', 'after_widget' => '</div>', 'before_title' => '<h4 class="widget-title">', 'after_title' => '</h4>'));
register_sidebar(array('name' => __('Posts 2', 'mh'), 'id' => 'posts-2', 'description' => __('Widget area below single post content', 'mh'), 'before_widget' => '<div class="sb-widget posts-2">', 'after_widget' => '</div>', 'before_title' => '<h4 class="widget-title">', 'after_title' => '</h4>'));
register_sidebar(array('name' => __('Pages 1', 'mh'), 'id' => 'pages-1', 'description' => __('Widget area above single page content', 'mh'), 'before_widget' => '<div class="sb-widget pages-1">', 'after_widget' => '</div>', 'before_title' => '<h4 class="widget-title">', 'after_title' => '</h4>'));
register_sidebar(array('name' => __('Pages 2', 'mh'), 'id' => 'pages-2', 'description' => __('Widget area below single page content', 'mh'), 'before_widget' => '<div class="sb-widget pages-2">', 'after_widget' => '</div>', 'before_title' => '<h4 class="widget-title">', 'after_title' => '</h4>'));
register_sidebar(array('name' => __('Footer 1', 'mh'), 'id' => 'footer-1', 'description' => __('Widget area in footer', 'mh'), 'before_widget' => '<div class="footer-widget footer-1">', 'after_widget' => '</div>', 'before_title' => '<h6 class="footer-widget-title">', 'after_title' => '</h6>'));
register_sidebar(array('name' => __('Footer 2', 'mh'), 'id' => 'footer-2', 'description' => __('Widget area in footer', 'mh'), 'before_widget' => '<div class="footer-widget footer-2">', 'after_widget' => '</div>', 'before_title' => '<h6 class="footer-widget-title">', 'after_title' => '</h6>'));
register_sidebar(array('name' => __('Footer 3', 'mh'), 'id' => 'footer-3', 'description' => __('Widget area in footer', 'mh'), 'before_widget' => '<div class="footer-widget footer-3">', 'after_widget' => '</div>', 'before_title' => '<h6 class="footer-widget-title">', 'after_title' => '</h6>'));
register_sidebar(array('name' => __('Footer 4', 'mh'), 'id' => 'footer-4', 'description' => __('Widget area in footer', 'mh'), 'before_widget' => '<div class="footer-widget footer-4">', 'after_widget' => '</div>', 'before_title' => '<h6 class="footer-widget-title">', 'after_title' => '</h6>'));
register_sidebar(array('name' => __('Contact', 'mh'), 'id' => 'contact', 'description' => __('Widget area (sidebar) on contact page template', 'mh'), 'before_widget' => '<div class="sb-widget contact">', 'after_widget' => '</div>', 'before_title' => '<h4 class="widget-title">', 'after_title' => '</h4>'));
if ($two_sidebars) {
register_sidebar(array('name' => __('Contact 2', 'mh'), 'id' => 'contact-2', 'description' => __('2nd widget area (sidebar) on contact page template', 'mh'), 'before_widget' => '<div class="sb-widget">', 'after_widget' => '</div>', 'before_title' => '<h4 class="widget-title">', 'after_title' => '</h4>'));
}
}
}
//* word count
function string_limit_words($string, $word_limit)
{
$words = explode(' ', $string, ($word_limit + 1));
if(count($words) > $word_limit) {
array_pop($words);
//add a ... at last article when more than limit word count
echo implode(' ', $words).""; } else {
//otherwise
echo implode(' ', $words); }
}
//* Post Counts
function PostViews($postID) {
$count_key = 'views';
$count = get_post_meta($postID, $count_key, true);
if($count==''){
$count = 0;
delete_post_meta($postID, $count_key);
add_post_meta($postID, $count_key, '2');
}else{
$count++;
update_post_meta($postID, $count_key, $count);
}
return $count; /* so you can show it */
}
function wpb_set_post_views($postID) {
$count_key = 'wpb_post_views_count';
$count = get_post_meta($postID, $count_key, true);
if($count==''){
$count = 0;
delete_post_meta($postID, $count_key);
add_post_meta($postID, $count_key, '0');
}else{
$count++;
update_post_meta($postID, $count_key, $count);
}
}
//To keep the count accurate, lets get rid of prefetching
remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0);
/***** Include Several Functions *****/
if (is_admin()) {
require_once('admin/admin.php');
}
require_once('includes/mh-head.php');
require_once('includes/mh-breadcrumb.php');
require_once('includes/mh-content.php');
require_once('includes/mh-options.php');
require_once('includes/mh-widgets.php');
require_once('includes/mh-custom-functions.php');
require_once('includes/mh-shortcodes.php');
?>