783 lines
30 KiB
PHP
783 lines
30 KiB
PHP
<?php
|
|
/*
|
|
* Original author: Todd Motto | @toddmotto
|
|
* Custom functions, support, custom post types and more.
|
|
*/
|
|
|
|
/*------------------------------------*\
|
|
External Modules/Files
|
|
\*------------------------------------*/
|
|
|
|
// Load any external files you have here
|
|
|
|
// Debug $data will display in console
|
|
function console_debug($data)
|
|
{
|
|
$data = json_encode($data);
|
|
echo "<script>console.dir($data)</script>";
|
|
}
|
|
|
|
/**
|
|
* Customizer additions.
|
|
*/
|
|
include get_template_directory() . '/customizer.php';
|
|
|
|
/*------------------------------------*\
|
|
Theme Support
|
|
\*------------------------------------*/
|
|
|
|
if (!isset($content_width)) {
|
|
$content_width = 900;
|
|
}
|
|
|
|
if (function_exists('add_theme_support')) {
|
|
// Add Menu Support
|
|
add_theme_support('menus');
|
|
|
|
// Add Thumbnail Theme Support
|
|
add_theme_support('post-thumbnails');
|
|
add_image_size('large', 700, '', true); // Large Thumbnail
|
|
add_image_size('medium', 250, '', true); // Medium Thumbnail
|
|
add_image_size('small', 120, '', true); // Small Thumbnail
|
|
add_image_size('home-big-thumbnail', 1024, 1024, true); // Custom Thumbnail Size call using the_post_thumbnail('home-thumbnail');
|
|
add_image_size('home-small-thumbnail', 256, 256, true); // Custom Thumbnail Size call using the_post_thumbnail('home-thumbnail');
|
|
add_image_size('home-event-thumbnail', 1024, 537, true);
|
|
add_image_size('single-thumbnail', 1366, 1280, true);
|
|
|
|
// Add Support for Custom Backgrounds - Uncomment below if you're going to use
|
|
/*add_theme_support('custom-background', array(
|
|
'default-color' => 'FFF',
|
|
'default-image' => get_template_directory_uri() . '/img/bg.jpg'
|
|
));*/
|
|
|
|
// Add Support for Custom Header - Uncomment below if you're going to use
|
|
/*add_theme_support('custom-header', array(
|
|
'default-image' => get_template_directory_uri() . '/img/headers/default.jpg',
|
|
'header-text' => false,
|
|
'default-text-color' => '000',
|
|
'width' => 1000,
|
|
'height' => 198,
|
|
'random-default' => false,
|
|
'wp-head-callback' => $wphead_cb,
|
|
'admin-head-callback' => $adminhead_cb,
|
|
'admin-preview-callback' => $adminpreview_cb
|
|
));*/
|
|
|
|
// Enables post and comment RSS feed links to head
|
|
add_theme_support('automatic-feed-links');
|
|
|
|
// Localisation Support
|
|
load_theme_textdomain('dis2019', get_template_directory() . '/languages');
|
|
}
|
|
|
|
/*------------------------------------*\
|
|
Functions
|
|
\*------------------------------------*/
|
|
|
|
// dis-2019 navigation
|
|
function dis2019_nav()
|
|
{
|
|
wp_nav_menu(
|
|
array(
|
|
'theme_location' => 'header-menu',
|
|
'menu' => '',
|
|
'container' => 'div',
|
|
'container_class' => 'menu-{menu slug}-container',
|
|
'container_id' => '',
|
|
'menu_class' => 'menu',
|
|
'menu_id' => '',
|
|
'echo' => true,
|
|
'fallback_cb' => 'wp_page_menu',
|
|
'before' => '',
|
|
'after' => '',
|
|
'link_before' => '',
|
|
'link_after' => '',
|
|
'items_wrap' => '<ul>%3$s</ul>',
|
|
'depth' => 0,
|
|
'walker' => '',
|
|
)
|
|
);
|
|
}
|
|
|
|
// Load dis-2019 scripts (header.php)
|
|
function dis2019_header_scripts()
|
|
{
|
|
if ($GLOBALS['pagenow'] != 'wp-login.php' && !is_admin()) {
|
|
|
|
wp_deregister_script('jquery');
|
|
wp_register_script('jquery', get_template_directory_uri() . '/js/lib/jquery-3.3.1.min.js', array(), '3.3.1');
|
|
|
|
// wp_register_script('conditionizr', get_template_directory_uri() . '/js/lib/conditionizr-4.3.0.min.js', array(), '4.3.0'); // Conditionizr
|
|
// wp_enqueue_script('conditionizr'); // Enqueue it!
|
|
|
|
wp_register_script('modernizr', get_template_directory_uri() . '/js/lib/modernizr-custom.js', array(), '2.7.1'); // Modernizr
|
|
wp_enqueue_script('modernizr'); // Enqueue it!
|
|
|
|
wp_register_script('simpler-sidebar', get_template_directory_uri() . '/js/lib/jquery.simpler-sidebar.min.js', array('jquery'), '2.2.5'); //
|
|
wp_enqueue_script('simpler-sidebar'); // Enqueue it!
|
|
|
|
wp_register_script('fittext', get_template_directory_uri() . '/js/lib/jquery.fittext.js', array('jquery'), '1.0.0'); //
|
|
wp_enqueue_script('fittext'); // Enqueue it!
|
|
|
|
wp_register_script('jquery.colorbox', get_template_directory_uri() . '/js/lib/jquery.colorbox-min.js', array('jquery'), '1.0.0'); //
|
|
wp_enqueue_script('jquery.colorbox'); // Enqueue it!
|
|
|
|
wp_register_script('lettering', get_template_directory_uri() . '/js/lib/jquery.lettering.js', array('jquery'), '1.0.0'); //
|
|
wp_enqueue_script('lettering'); // Enqueue it!
|
|
|
|
// wp_register_script('clamp', get_template_directory_uri() . '/js/lib/clamp.min.js', array(), '1.5.1'); //
|
|
// wp_enqueue_script('clamp'); // Enqueue it!
|
|
|
|
wp_register_script('ftellipsis', get_template_directory_uri() . '/js/lib/ftellipsis.min.js', array(), '1.0.0'); //
|
|
wp_enqueue_script('ftellipsis'); // Enqueue it!
|
|
|
|
wp_register_script('touchSwipe', get_template_directory_uri() . '/js/lib/jquery.touchSwipe-1.6.18.min.js', array('jquery'), '1.6.19'); //
|
|
wp_enqueue_script('touchSwipe'); // Enqueue it!
|
|
|
|
wp_register_script('dis2019scripts', get_template_directory_uri() . '/js/scripts.js', array(
|
|
'jquery',
|
|
// 'conditionizr',
|
|
'modernizr',
|
|
'simpler-sidebar',
|
|
'fittext',
|
|
'jquery.colorbox',
|
|
'lettering',
|
|
'ftellipsis',
|
|
'touchSwipe',
|
|
// 'clamp',
|
|
), '1.0.0'); // Custom scripts
|
|
wp_enqueue_script('dis2019scripts'); // Enqueue it!
|
|
}
|
|
}
|
|
|
|
// Load dis-2019 conditional scripts
|
|
function dis2019_conditional_scripts()
|
|
{
|
|
if (is_page('pagenamehere')) {
|
|
wp_register_script('scriptname', get_template_directory_uri() . '/js/scriptname.js', array('jquery'), '1.0.0'); // Conditional script(s)
|
|
wp_enqueue_script('scriptname'); // Enqueue it!
|
|
}
|
|
}
|
|
|
|
// Load dis-2019 styles
|
|
function dis2019_styles()
|
|
{
|
|
wp_register_style('normalize', get_template_directory_uri() . '/css/normalize.min.css', array(), '1.0', 'all');
|
|
wp_enqueue_style('normalize'); // Enqueue it!
|
|
|
|
wp_register_style('dis2019', get_template_directory_uri() . '/style.css', array(), '1.0', 'all');
|
|
wp_enqueue_style('dis2019'); // Enqueue it!
|
|
|
|
// wp_register_style('drawer', get_template_directory_uri() . '/css/drawer.min.css', array(), '1.0', 'all');
|
|
// wp_enqueue_style('drawer'); // Enqueue it!
|
|
|
|
wp_register_style('base', get_template_directory_uri() . '/css/base.css', array(), '1.0', 'all');
|
|
wp_enqueue_style('base'); // Enqueue it!
|
|
|
|
}
|
|
|
|
// Register dis-2019 Navigation
|
|
function register_dis_menu()
|
|
{
|
|
register_nav_menus(array( // Using array to specify more menus if needed
|
|
'main-left-menu' => __('Main menu left', 'dis2019'), // Main Navigation
|
|
'main-right-menu' => __('Main menu right', 'dis2019'), // Extra Navigation if needed (duplicate as many as you need!)
|
|
// 'sidebar-menu' => __('Sidebar Menu', 'dis2019'), // Sidebar Navigation
|
|
'tag-menu' => __('Circular tags', 'dis2019'), // bedo circle
|
|
//'main-right-menu' => __('Header Right Menu', 'dis2019'), // Extra Navigation if needed (duplicate as many as you need!)
|
|
));
|
|
}
|
|
|
|
// Remove the <div> surrounding the dynamic navigation to cleanup markup
|
|
function my_wp_nav_menu_args($args = '')
|
|
{
|
|
$args['container'] = false;
|
|
return $args;
|
|
}
|
|
|
|
// Remove Injected classes, ID's and Page ID's from Navigation <li> items
|
|
function my_css_attributes_filter($var)
|
|
{
|
|
return is_array($var) ? array() : '';
|
|
}
|
|
|
|
// Remove invalid rel attribute values in the categorylist
|
|
function remove_category_rel_from_category_list($thelist)
|
|
{
|
|
return str_replace('rel="category tag"', 'rel="tag"', $thelist);
|
|
}
|
|
|
|
// Add page slug to body class, love this - Credit: Starkers Wordpress Theme
|
|
function add_slug_to_body_class($classes)
|
|
{
|
|
global $post;
|
|
if (is_home()) {
|
|
$key = array_search('blog', $classes);
|
|
if ($key > -1) {
|
|
unset($classes[$key]);
|
|
}
|
|
} elseif (is_page()) {
|
|
$classes[] = sanitize_html_class($post->post_name);
|
|
} elseif (is_singular()) {
|
|
$classes[] = sanitize_html_class($post->post_name);
|
|
}
|
|
|
|
// array_push($classes,"drawer","drawer--right");
|
|
return $classes;
|
|
}
|
|
|
|
function add_masonry_to_body_class( $classes ) {
|
|
if(is_home() || is_archive() || is_search() || is_404()){
|
|
$classes[] = 'masonrypage';
|
|
} else if(is_singular()){
|
|
$classes[] = 'singularpage';
|
|
}
|
|
return $classes;
|
|
}
|
|
|
|
// // If Dynamic Sidebar Exists
|
|
// if (function_exists('register_sidebar'))
|
|
// {
|
|
// // Define Sidebar Widget Area 1
|
|
// register_sidebar(array(
|
|
// 'name' => __('Widget Area 1', 'dis2019'),
|
|
// 'description' => __('Description for this widget-area...', 'dis2019'),
|
|
// 'id' => 'widget-area-1',
|
|
// 'before_widget' => '<div id="%1$s" class="%2$s">',
|
|
// 'after_widget' => '</div>',
|
|
// 'before_title' => '<h3>',
|
|
// 'after_title' => '</h3>'
|
|
// ));
|
|
|
|
// // Define Sidebar Widget Area 2
|
|
// register_sidebar(array(
|
|
// 'name' => __('Widget Area 2', 'dis2019'),
|
|
// 'description' => __('Description for this widget-area...', 'dis2019'),
|
|
// 'id' => 'widget-area-2',
|
|
// 'before_widget' => '<div id="%1$s" class="%2$s">',
|
|
// 'after_widget' => '</div>',
|
|
// 'before_title' => '<h3>',
|
|
// 'after_title' => '</h3>'
|
|
// ));
|
|
// }
|
|
|
|
// Remove wp_head() injected Recent Comment styles
|
|
function my_remove_recent_comments_style()
|
|
{
|
|
global $wp_widget_factory;
|
|
remove_action('wp_head', array(
|
|
$wp_widget_factory->widgets['WP_Widget_Recent_Comments'],
|
|
'recent_comments_style',
|
|
));
|
|
}
|
|
|
|
// Pagination for paged posts, Page 1, Page 2, Page 3, with Next and Previous Links, No plugin
|
|
function diswp_pagination()
|
|
{
|
|
global $wp_query;
|
|
$big = 999999999;
|
|
echo paginate_links(array(
|
|
'base' => str_replace($big, '%#%', get_pagenum_link($big)),
|
|
'format' => '?paged=%#%',
|
|
'current' => max(1, get_query_var('paged')),
|
|
'total' => $wp_query->max_num_pages,
|
|
));
|
|
}
|
|
|
|
// Custom Excerpts
|
|
function diswp_index($length) // Create 20 Word Callback for Index page Excerpts, call using diswp_excerpt('diswp_index');
|
|
|
|
{
|
|
return 20;
|
|
}
|
|
|
|
// Create 40 Word Callback for Custom Post Excerpts, call using diswp_excerpt('diswp_custom_post');
|
|
function diswp_custom_post($length)
|
|
{
|
|
return 40;
|
|
}
|
|
|
|
// Create the Custom Excerpts callback
|
|
function diswp_excerpt($length_callback = '', $more_callback = '')
|
|
{
|
|
global $post;
|
|
if (function_exists($length_callback)) {
|
|
add_filter('excerpt_length', $length_callback);
|
|
}
|
|
if (function_exists($more_callback)) {
|
|
add_filter('excerpt_more', $more_callback);
|
|
}
|
|
$output = get_the_excerpt();
|
|
$output = apply_filters('wptexturize', $output);
|
|
$output = apply_filters('convert_chars', $output);
|
|
$output = '<p>' . $output . '</p>';
|
|
echo $output;
|
|
}
|
|
|
|
// Custom View Article link to Post
|
|
function dis_blank_view_article($more)
|
|
{
|
|
global $post;
|
|
return '... <a class="view-article" href="' . get_permalink($post->ID) . '">' . __('View Article', 'dis2019') . '</a>';
|
|
}
|
|
|
|
// Remove Admin bar
|
|
function remove_admin_bar()
|
|
{
|
|
return false;
|
|
}
|
|
|
|
// Remove 'text/css' from our enqueued stylesheet
|
|
function dis_style_remove($tag)
|
|
{
|
|
return preg_replace('~\s+type=["\'][^"\']++["\']~', '', $tag);
|
|
}
|
|
|
|
// Remove thumbnail width and height dimensions that prevent fluid images in the_thumbnail
|
|
function remove_thumbnail_dimensions($html)
|
|
{
|
|
$html = preg_replace('/(width|height)=\"\d*\"\s/', "", $html);
|
|
return $html;
|
|
}
|
|
|
|
//Wrap aligned images to a div
|
|
function wrap_aligned_images($content)
|
|
{
|
|
return preg_replace('/<div class="wp-block-image"><figure class="(align[a-z]*)([ "])(.*)<\/figure>\s*/iU', '<div class="wp-block-image wp-block-image-aligned"><div class="alignedWrapper \1Wrapper"><figure class="\1\2\3 </figure></div>', $content);
|
|
}
|
|
add_filter('the_content', 'wrap_aligned_images');
|
|
|
|
// Custom Gravatar in Settings > Discussion
|
|
function dis2019gravatar($avatar_defaults)
|
|
{
|
|
$myavatar = get_template_directory_uri() . '/img/gravatar.jpg';
|
|
$avatar_defaults[$myavatar] = "Custom Gravatar";
|
|
return $avatar_defaults;
|
|
}
|
|
|
|
// Threaded Comments
|
|
function enable_threaded_comments()
|
|
{
|
|
if (!is_admin()) {
|
|
if (is_singular() and comments_open() and (get_option('thread_comments') == 1)) {
|
|
wp_enqueue_script('comment-reply');
|
|
}
|
|
}
|
|
}
|
|
|
|
// Custom Comments Callback
|
|
function dis2019comments($comment, $args, $depth)
|
|
{
|
|
$GLOBALS['comment'] = $comment;
|
|
extract($args, EXTR_SKIP);
|
|
|
|
if ('div' == $args['style']) {
|
|
$tag = 'div';
|
|
$add_below = 'comment';
|
|
} else {
|
|
$tag = 'li';
|
|
$add_below = 'div-comment';
|
|
}
|
|
?>
|
|
<!-- heads up: starting < for the html tag (li or div) in the next line: -->
|
|
<<?php echo $tag ?> <?php comment_class(empty($args['has_children']) ? '' : 'parent')?> id="comment-<?php comment_ID()?>">
|
|
<?php if ('div' != $args['style']): ?>
|
|
<div id="div-comment-<?php comment_ID()?>" class="comment-body">
|
|
<?php endif;?>
|
|
<div class="comment-author vcard">
|
|
<?php if ($args['avatar_size'] != 0) {
|
|
echo get_avatar($comment, $args['180']);
|
|
}
|
|
?>
|
|
<?php printf(__('<cite class="fn">%s</cite> <span class="says">says:</span>'), get_comment_author_link())?>
|
|
</div>
|
|
<?php if ($comment->comment_approved == '0'): ?>
|
|
<em class="comment-awaiting-moderation"><?php _e('Your comment is awaiting moderation.')?></em>
|
|
<br />
|
|
<?php endif;?>
|
|
|
|
<div class="comment-meta commentmetadata"><a href="<?php echo htmlspecialchars(get_comment_link($comment->comment_ID)) ?>">
|
|
<?php
|
|
printf(__('%1$s at %2$s'), get_comment_date(), get_comment_time())?></a><?php edit_comment_link(__('(Edit)'), ' ', '');
|
|
?>
|
|
</div>
|
|
|
|
<?php comment_text()?>
|
|
|
|
<div class="reply">
|
|
<?php comment_reply_link(array_merge($args, array('add_below' => $add_below, 'depth' => $depth, 'max_depth' => $args['max_depth'])))?>
|
|
</div>
|
|
<?php if ('div' != $args['style']): ?>
|
|
</div>
|
|
<?php endif;?>
|
|
<?php }
|
|
|
|
/* -------------------------------------------------------------------------- */
|
|
/* INFINITE SCROLL */
|
|
/* -------------------------------------------------------------------------- */
|
|
|
|
function misha_my_load_more_scripts()
|
|
{
|
|
|
|
global $wp_query;
|
|
|
|
// In most cases it is already included on the page and this line can be removed
|
|
//wp_enqueue_script('jquery');
|
|
|
|
// register our main script but do not enqueue it yet
|
|
//wp_register_script('my_loadmore', get_stylesheet_directory_uri() . '/js/myloadmore.js', array('jquery'));
|
|
|
|
// now the most interesting part
|
|
// we have to pass parameters to myloadmore.js script but we can get the parameters values only in PHP
|
|
// you can define variables directly in your HTML but I decided that the most proper way is wp_localize_script()
|
|
//wp_localize_script('my_loadmore', 'misha_loadmore_params', array(
|
|
wp_localize_script('dis2019scripts', 'misha_loadmore_params', array(
|
|
|
|
'ajaxurl' => site_url() . '/wp-admin/admin-ajax.php', // WordPress AJAX
|
|
'posts' => json_encode($wp_query->query_vars), // everything about your loop is here
|
|
'current_page' => get_query_var('paged') ? get_query_var('paged') : 1,
|
|
'max_page' => $wp_query->max_num_pages,
|
|
));
|
|
|
|
// wp_enqueue_script('my_loadmore');
|
|
}
|
|
|
|
add_action('wp_enqueue_scripts', 'misha_my_load_more_scripts');
|
|
|
|
function misha_loadmore_ajax_handler()
|
|
{
|
|
|
|
// prepare our arguments for the query
|
|
$args = json_decode(stripslashes($_POST['query']), true);
|
|
$args['paged'] = $_POST['page'] + 1; // we need next page to be loaded
|
|
$args['post_status'] = 'publish';
|
|
$args['posts_per_page'] = 6;
|
|
|
|
//First, define your desired offset...
|
|
$offset = get_theme_mod('dis-2019-posts-on-home');
|
|
|
|
// console_debug($args);
|
|
if ($args['cat']) {
|
|
// console_debug('cat query');
|
|
$offset = get_theme_mod('dis-2019-posts-on-archive', 11);
|
|
}
|
|
if ($args['s']) {
|
|
// console_debug('search query');
|
|
$offset = get_theme_mod('dis-2019-posts-on-archive', 11);
|
|
}
|
|
|
|
if ($args['tag']) {
|
|
// console_debug('tag query');
|
|
$offset = get_theme_mod('dis-2019-posts-on-tag', 10);
|
|
}
|
|
|
|
//Next, determine how many posts per page you want (we'll use WordPress's settings)
|
|
$ppp = get_option('posts_per_page');
|
|
|
|
//Next, detect and handle pagination...
|
|
|
|
//Manually determine page query offset (offset + current page (minus one) x posts per page)
|
|
$args['offset'] = $offset + (($_POST['page'] - 1) * $ppp);
|
|
|
|
query_posts($args);
|
|
get_template_part('loop');
|
|
|
|
die; // here we exit the script and even no wp_reset_query() required!
|
|
}
|
|
|
|
add_action('wp_ajax_loadmore', 'misha_loadmore_ajax_handler'); // wp_ajax_{action}
|
|
add_action('wp_ajax_nopriv_loadmore', 'misha_loadmore_ajax_handler'); // wp_ajax_nopriv_{action}
|
|
|
|
/* -------------------------------------------------------------------------- */
|
|
/* pre_get_posts */
|
|
/* -------------------------------------------------------------------------- */
|
|
|
|
//remove events from home page
|
|
function exclude_category_home($query)
|
|
{
|
|
if ($query->is_home) {
|
|
$minus_catid = '-' . get_theme_mod('dis-2019-event-cat-id', 5);
|
|
$query->set('cat', $minus_catid);
|
|
|
|
}
|
|
return $query;
|
|
}
|
|
add_filter('pre_get_posts', 'exclude_category_home');
|
|
|
|
// order events by date on events page
|
|
function dis_2019_order_events_by_date(&$query)
|
|
{
|
|
|
|
//Before anything else, make sure this is the right query...
|
|
if (!($query->query_vars[category_name] == get_theme_mod('dis-2019-event-cat-slug', 'esemeny'))) {
|
|
return;
|
|
}
|
|
|
|
$query->set('meta_key', 'dis-esemeny-datum');
|
|
$query->set('orderby', 'meta_value');
|
|
$query->set('order', 'ASC');
|
|
$query->set('meta_value', date("Y.m.d.")); // change to how "event date" is stored
|
|
$query->set('meta_compare', '>');
|
|
}
|
|
add_action('pre_get_posts', 'dis_2019_order_events_by_date', 1);
|
|
|
|
/* -------------------- different number of posts on home ------------------- */
|
|
|
|
add_action('pre_get_posts', 'dis_2019_more_posts_on_home', 1);
|
|
function dis_2019_more_posts_on_home(&$query)
|
|
{
|
|
|
|
|
|
//Before anything else, make sure this is the right query...
|
|
if (!$query->is_home() && !$query->is_archive() && !$query->is_search()) {
|
|
return;
|
|
}
|
|
|
|
// if it's a menu
|
|
if ($query->query_vars[orderby] == 'menu_order') {
|
|
return;
|
|
}
|
|
|
|
|
|
|
|
//console_debug($query);
|
|
// console_debug($query->query_vars[related_loop]);
|
|
|
|
|
|
if ($query->is_home()) {
|
|
$pposts = get_theme_mod('dis-2019-posts-on-home',20);
|
|
} elseif ($query->is_tag()) {
|
|
$pposts = get_theme_mod('dis-2019-posts-on-tag', 10);
|
|
} elseif ($query->query_vars[related_loop]) {
|
|
$pposts = get_theme_mod('dis-2019-related-posts', 3);
|
|
} elseif ($query->is_archive()) {
|
|
$pposts = get_theme_mod('dis-2019-posts-on-archive', 11);
|
|
} elseif ($query->is_search()) {
|
|
$pposts = get_theme_mod('dis-2019-posts-on-archive', 11);
|
|
} elseif (!$query->in_the_loop()) {
|
|
return;
|
|
} else {
|
|
$pposts = get_option('posts_per_page');
|
|
// $pposts = 6;
|
|
}
|
|
|
|
//set post_per_page if it's homepage
|
|
if (!$query->is_paged) {
|
|
// console_debug($pposts);
|
|
$query->set('posts_per_page', $pposts);
|
|
} else {
|
|
return;
|
|
}
|
|
}
|
|
|
|
// add_filter('found_posts', 'myprefix_adjust_offset_pagination', 1, 2 );
|
|
// function myprefix_adjust_offset_pagination($found_posts, $query) {
|
|
|
|
// //Define our offset again...
|
|
// $offset = 2;
|
|
|
|
// //Ensure we're modifying the right query object...
|
|
// if ( $query->is_home() ) {
|
|
// //Reduce WordPress's found_posts count by the offset...
|
|
// return $found_posts - $offset;
|
|
// }
|
|
// return $found_posts;
|
|
// }
|
|
|
|
/*------------------------------------*\
|
|
Actions + Filters + ShortCodes
|
|
\*------------------------------------*/
|
|
|
|
// Add Actions
|
|
add_action('init', 'dis2019_header_scripts'); // Add Custom Scripts to wp_head
|
|
add_action('wp_print_scripts', 'dis2019_conditional_scripts'); // Add Conditional Page Scripts
|
|
add_action('get_header', 'enable_threaded_comments'); // Enable Threaded Comments
|
|
add_action('wp_enqueue_scripts', 'dis2019_styles'); // Add Theme Stylesheet
|
|
add_action('init', 'register_dis_menu'); // Add dis-2019 Menu
|
|
//add_action('init', 'create_post_type_dis'); // Add our dis-2019 Custom Post Type
|
|
add_action('widgets_init', 'my_remove_recent_comments_style'); // Remove inline Recent Comment Styles from wp_head()
|
|
add_action('init', 'diswp_pagination'); // Add our HTML5 Pagination
|
|
|
|
// Remove Actions
|
|
remove_action('wp_head', 'feed_links_extra', 3); // Display the links to the extra feeds such as category feeds
|
|
remove_action('wp_head', 'feed_links', 2); // Display the links to the general feeds: Post and Comment Feed
|
|
remove_action('wp_head', 'rsd_link'); // Display the link to the Really Simple Discovery service endpoint, EditURI link
|
|
remove_action('wp_head', 'wlwmanifest_link'); // Display the link to the Windows Live Writer manifest file.
|
|
remove_action('wp_head', 'index_rel_link'); // Index link
|
|
remove_action('wp_head', 'parent_post_rel_link', 10, 0); // Prev link
|
|
remove_action('wp_head', 'start_post_rel_link', 10, 0); // Start link
|
|
remove_action('wp_head', 'adjacent_posts_rel_link', 10, 0); // Display relational links for the posts adjacent to the current post.
|
|
remove_action('wp_head', 'wp_generator'); // Display the XHTML generator that is generated on the wp_head hook, WP version
|
|
remove_action('wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0);
|
|
remove_action('wp_head', 'rel_canonical');
|
|
remove_action('wp_head', 'wp_shortlink_wp_head', 10, 0);
|
|
|
|
// Add Filters
|
|
add_filter('avatar_defaults', 'dis2019gravatar'); // Custom Gravatar in Settings > Discussion
|
|
add_filter('body_class', 'add_slug_to_body_class'); // Add slug to body class (Starkers build)
|
|
add_filter('body_class', 'add_masonry_to_body_class'); // Add masonry to body class
|
|
add_filter('widget_text', 'do_shortcode'); // Allow shortcodes in Dynamic Sidebar
|
|
add_filter('widget_text', 'shortcode_unautop'); // Remove <p> tags in Dynamic Sidebars (better!)
|
|
add_filter('wp_nav_menu_args', 'my_wp_nav_menu_args'); // Remove surrounding <div> from WP Navigation
|
|
// add_filter('nav_menu_css_class', 'my_css_attributes_filter', 100, 1); // Remove Navigation <li> injected classes (Commented out by default)
|
|
// add_filter('nav_menu_item_id', 'my_css_attributes_filter', 100, 1); // Remove Navigation <li> injected ID (Commented out by default)
|
|
// add_filter('page_css_class', 'my_css_attributes_filter', 100, 1); // Remove Navigation <li> Page ID's (Commented out by default)
|
|
add_filter('the_category', 'remove_category_rel_from_category_list'); // Remove invalid rel attribute
|
|
add_filter('the_excerpt', 'shortcode_unautop'); // Remove auto <p> tags in Excerpt (Manual Excerpts only)
|
|
add_filter('the_excerpt', 'do_shortcode'); // Allows Shortcodes to be executed in Excerpt (Manual Excerpts only)
|
|
add_filter('excerpt_more', 'dis_blank_view_article'); // Add 'View Article' button instead of [...] for Excerpts
|
|
add_filter('show_admin_bar', 'remove_admin_bar'); // Remove Admin bar
|
|
add_filter('style_loader_tag', 'dis_style_remove'); // Remove 'text/css' from enqueued stylesheet
|
|
add_filter('post_thumbnail_html', 'remove_thumbnail_dimensions', 10); // Remove width and height dynamic attributes to thumbnails
|
|
add_filter('image_send_to_editor', 'remove_thumbnail_dimensions', 10); // Remove width and height dynamic attributes to post images
|
|
|
|
// Remove Filters
|
|
remove_filter('the_excerpt', 'wpautop'); // Remove <p> tags from Excerpt altogether
|
|
|
|
// Shortcodes
|
|
add_shortcode('dis_shortcode_demo', 'dis_shortcode_demo'); // You can place [dis_shortcode_demo] in Pages, Posts now.
|
|
add_shortcode('dis_shortcode_demo_2', 'dis_shortcode_demo_2'); // Place [dis_shortcode_demo_2] in Pages, Posts now.
|
|
|
|
// Shortcodes above would be nested like this -
|
|
// [dis_shortcode_demo] [dis_shortcode_demo_2] Here's the page title! [/dis_shortcode_demo_2] [/dis_shortcode_demo]
|
|
|
|
/*------------------------------------*\
|
|
Custom Post Types
|
|
\*------------------------------------*/
|
|
|
|
// Create 1 Custom Post type for a Demo, called HTML5-Blank
|
|
// function create_post_type_dis()
|
|
// {
|
|
// register_taxonomy_for_object_type('category', 'dis-blank'); // Register Taxonomies for Category
|
|
// register_taxonomy_for_object_type('post_tag', 'dis-blank');
|
|
// register_post_type('dis-blank', // Register Custom Post Type
|
|
// array(
|
|
// 'labels' => array(
|
|
// 'name' => __('dis-2019 Custom Post', 'dis2019'), // Rename these to suit
|
|
// 'singular_name' => __('dis-2019 Custom Post', 'dis2019'),
|
|
// 'add_new' => __('Add New', 'dis2019'),
|
|
// 'add_new_item' => __('Add New dis-2019 Custom Post', 'dis2019'),
|
|
// 'edit' => __('Edit', 'dis2019'),
|
|
// 'edit_item' => __('Edit dis-2019 Custom Post', 'dis2019'),
|
|
// 'new_item' => __('New dis-2019 Custom Post', 'dis2019'),
|
|
// 'view' => __('View dis-2019 Custom Post', 'dis2019'),
|
|
// 'view_item' => __('View dis-2019 Custom Post', 'dis2019'),
|
|
// 'search_items' => __('Search dis-2019 Custom Post', 'dis2019'),
|
|
// 'not_found' => __('No dis-2019 Custom Posts found', 'dis2019'),
|
|
// 'not_found_in_trash' => __('No dis-2019 Custom Posts found in Trash', 'dis2019')
|
|
// ),
|
|
// 'public' => true,
|
|
// 'hierarchical' => true, // Allows your posts to behave like Hierarchy Pages
|
|
// 'has_archive' => true,
|
|
// 'supports' => array(
|
|
// 'title',
|
|
// 'editor',
|
|
// 'excerpt',
|
|
// 'thumbnail'
|
|
// ), // Go to Dashboard Custom dis-2019 post for supports
|
|
// 'can_export' => true, // Allows export in Tools > Export
|
|
// 'taxonomies' => array(
|
|
// 'post_tag',
|
|
// 'category'
|
|
// ) // Add Category and Post Tags support
|
|
// ));
|
|
// }
|
|
|
|
/*------------------------------------*\
|
|
ShortCode Functions
|
|
\*------------------------------------*/
|
|
|
|
// Shortcode Demo with Nested Capability
|
|
function dis_shortcode_demo($atts, $content = null)
|
|
{
|
|
return '<div class="shortcode-demo">' . do_shortcode($content) . '</div>'; // do_shortcode allows for nested Shortcodes
|
|
}
|
|
|
|
// Shortcode Demo with simple <h2> tag
|
|
function dis_shortcode_demo_2($atts, $content = null) // Demo Heading H2 shortcode, allows for nesting within above element. Fully expandable.
|
|
|
|
{
|
|
return '<h2>' . $content . '</h2>';
|
|
}
|
|
|
|
/*------------------------------------*\
|
|
Custom taxonomy
|
|
\*------------------------------------*/
|
|
|
|
function dis2019_register_taxonomy_format()
|
|
{
|
|
$labels = [
|
|
'name' => _x('Format', 'taxonomy general name', 'dis2019'),
|
|
'singular_name' => _x('Format', 'taxonomy singular name', 'dis2019'),
|
|
'search_items' => __('Search Formats', 'dis2019'),
|
|
'all_items' => __('All Formats', 'dis2019'),
|
|
'parent_item' => __('Parent Format', 'dis2019'),
|
|
'parent_item_colon' => __('Parent Format:', 'dis2019'),
|
|
'edit_item' => __('Edit Format', 'dis2019'),
|
|
'update_item' => __('Update Format', 'dis2019'),
|
|
'add_new_item' => __('Add New Format', 'dis2019'),
|
|
'new_item_name' => __('New Format Name', 'dis2019'),
|
|
'menu_name' => __('Formats', 'dis2019'),
|
|
|
|
'view_item' => __('View Formats', 'dis2019'),
|
|
'popular_items' => __('Popular Formats', 'dis2019'),
|
|
'separate_items_with_commas' => __('Separate formats with commas', 'dis2019'),
|
|
'add_or_remove_items' => __('Add or remove formats', 'dis2019'),
|
|
'choose_from_most_used' => __('Choose from most used formats', 'dis2019'),
|
|
'not_found' => __('No formats found', 'dis2019'),
|
|
'back_to_items' => __('Back to formats', 'dis2019'),
|
|
];
|
|
$args = [
|
|
'hierarchical' => false, // make it hierarchical (like categories)
|
|
'labels' => $labels,
|
|
'show_ui' => true,
|
|
'show_admin_column' => true,
|
|
'query_var' => true,
|
|
'rewrite' => ['slug' => 'format'],
|
|
'show_in_rest' => true,
|
|
'public' => true,
|
|
];
|
|
register_taxonomy('Format', ['post'], $args);
|
|
}
|
|
add_action('init', 'dis2019_register_taxonomy_format');
|
|
|
|
function dis2019_register_taxonomy_writer()
|
|
{
|
|
$labels = [
|
|
'name' => _x('Writers', 'taxonomy general name', 'dis2019'),
|
|
'singular_name' => _x('Writer', 'taxonomy singular name', 'dis2019'),
|
|
'search_items' => __('Search Writers', 'dis2019'),
|
|
'all_items' => __('All Writers', 'dis2019'),
|
|
'parent_item' => __('Parent Writer', 'dis2019'),
|
|
'parent_item_colon' => __('Parent Writer:', 'dis2019'),
|
|
'edit_item' => __('Edit Writer', 'dis2019'),
|
|
'update_item' => __('Update Writer', 'dis2019'),
|
|
'add_new_item' => __('Add New Writer', 'dis2019'),
|
|
'new_item_name' => __('New Writer Name', 'dis2019'),
|
|
'menu_name' => __('Writers', 'dis2019'),
|
|
|
|
'view_item' => __('View Writers', 'dis2019'),
|
|
'popular_items' => __('Popular Writers', 'dis2019'),
|
|
'separate_items_with_commas' => __('Separate writers with commas', 'dis2019'),
|
|
'add_or_remove_items' => __('Add or remove writers', 'dis2019'),
|
|
'choose_from_most_used' => __('Choose from most used writer', 'dis2019'),
|
|
'not_found' => __('No writer found', 'dis2019'),
|
|
'back_to_items' => __('Back to writers', 'dis2019'),
|
|
|
|
];
|
|
$args = [
|
|
'hierarchical' => false, // make it hierarchical (like categories)
|
|
'labels' => $labels,
|
|
'show_ui' => true,
|
|
'show_admin_column' => true,
|
|
'query_var' => true,
|
|
'rewrite' => ['slug' => 'writer'],
|
|
'show_in_rest' => true,
|
|
'public' => true,
|
|
];
|
|
register_taxonomy('Writer', ['post'], $args);
|
|
}
|
|
add_action('init', 'dis2019_register_taxonomy_writer');
|
|
|
|
?>
|