portage/functions.php

236 lines
7.8 KiB
PHP
Raw Normal View History

2021-08-01 17:32:46 +00:00
<?php
/**
* Atticus Finch functions and definitions
*
2021-08-01 17:55:17 +00:00
* @package Portage
2021-08-01 17:32:46 +00:00
*/
2021-08-01 17:55:17 +00:00
if ( ! function_exists( 'portage_setup' ) ) :
2021-08-01 17:32:46 +00:00
/**
* Sets up theme defaults and registers support for various WordPress features.
*
* Note that this function is hooked into the after_setup_theme hook, which
* runs before the init hook. The init hook is too late for some features, such
* as indicating support for post thumbnails.
*/
2021-08-01 17:55:17 +00:00
function portage_setup() {
2021-08-01 17:32:46 +00:00
/*
* Make theme available for translation.
* Translations can be filed in the /languages/ directory.
* If you're building a theme based on Atticus Finch, use a find and replace
2021-08-01 17:55:17 +00:00
* to change 'portage' to the name of your theme in all the template files
2021-08-01 17:32:46 +00:00
*/
2021-08-01 17:55:17 +00:00
load_theme_textdomain( 'portage', get_template_directory() . '/lang' );
2021-08-01 17:32:46 +00:00
// 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 <title> 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 http://codex.wordpress.org/Function_Reference/add_theme_support#Post_Thumbnails
*/
add_theme_support( 'post-thumbnails' );
// This theme uses wp_nav_menu() in three locations.
register_nav_menus( array(
2021-08-01 17:55:17 +00:00
'top-menu' => esc_html__( 'Top Menu', 'portage' ),
'primary-menu' => esc_html__( 'Primary Menu', 'portage' ),
'footer-menu' => esc_html__( 'Footer Menu', 'portage' ),
2021-08-01 17:32:46 +00:00
) );
/*
* Switch default core markup for search form, comment form, and comments
* to output valid HTML5.
*/
add_theme_support( 'html5', array(
'search-form',
'comment-form',
'comment-list',
'gallery',
'caption',
) );
/*
* Enable support for Post Formats.
* See http://codex.wordpress.org/Post_Formats
*/
add_theme_support( 'post-formats', array(
'aside',
'audio',
'chat',
'gallery',
'image',
'link',
'quote',
'status',
'video',
) );
// Set up the WordPress core custom background feature.
2021-08-01 17:55:17 +00:00
add_theme_support( 'custom-background', apply_filters( 'portage_custom_background_args', array(
2021-08-01 17:32:46 +00:00
'default-color' => 'ffffff',
'default-image' => '',
) ) );
}
2021-08-01 17:55:17 +00:00
endif; // portage_setup
add_action( 'after_setup_theme', 'portage_setup' );
2021-08-01 17:32:46 +00:00
/**
* Set the content width in pixels, based on the theme's design and stylesheet.
*
* Priority 0 to make it available to lower priority callbacks.
*
* @global int $content_width
*/
2021-08-01 17:55:17 +00:00
function portage_content_width() {
$GLOBALS['content_width'] = apply_filters( 'portage_content_width', 620 );
2021-08-01 17:32:46 +00:00
}
2021-08-01 17:55:17 +00:00
add_action( 'after_setup_theme', 'portage_content_width', 0 );
2021-08-01 17:32:46 +00:00
/**
* Register widget area.
*
* @link http://codex.wordpress.org/Function_Reference/register_sidebar
*/
2021-08-01 17:55:17 +00:00
function portage_widgets_init() {
2021-08-01 17:32:46 +00:00
register_sidebar( array(
2021-08-01 17:55:17 +00:00
'name' => esc_html__( 'Sidebar', 'portage' ),
2021-08-01 17:32:46 +00:00
'id' => 'sidebar-1',
'description' => '',
'before_widget' => '',
'after_widget' => '',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
) );
}
2021-08-01 17:55:17 +00:00
add_action( 'widgets_init', 'portage_widgets_init' );
2021-08-01 17:32:46 +00:00
/**
* Enqueue scripts and styles.
*/
2021-08-01 17:55:17 +00:00
function portage_scripts() {
wp_enqueue_style( 'portage-googlefont', 'https://fonts.googleapis.com/css?family=IM+Fell+English:400,400italic', 'portage-style', wp_get_theme() -> get( 'Version' ), 'all' );
2021-08-01 17:32:46 +00:00
if ( !wp_style_is( 'font-awesome.min.css', 'enqueued' ) ) {
2021-08-01 17:55:17 +00:00
wp_enqueue_style( 'portage-fa', 'https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css', 'portage-style', wp_get_theme() -> get( 'Version' ), 'all' );
2021-08-01 17:32:46 +00:00
}
2021-08-01 17:55:17 +00:00
wp_enqueue_style( 'portage-style', get_stylesheet_uri() );
2021-08-01 17:32:46 +00:00
2021-08-01 17:55:17 +00:00
wp_enqueue_style( 'portage-menus', get_template_directory_uri() . '/styles/menus.css', array( 'portage-style' ), wp_get_theme() -> get( 'Version' ) );
2021-08-01 17:32:46 +00:00
2021-08-01 17:55:17 +00:00
wp_enqueue_style( 'portage-mobile', get_template_directory_uri() . '/styles/mobile.css', array( 'portage-style' ), wp_get_theme() -> get( 'Version' ), 'screen and (max-width: '. get_theme_mod( 'portage_mobile_breakpoint' ) . 'px)' );
2021-08-01 17:32:46 +00:00
2021-08-01 17:55:17 +00:00
wp_enqueue_style( 'portage-print', get_template_directory_uri() . '/styles/print.css', array( 'portage-style' ), wp_get_theme() -> get( 'Version' ), 'print' );
2021-08-01 17:32:46 +00:00
2021-08-01 17:55:17 +00:00
wp_enqueue_script( 'portage-menumaker', get_template_directory_uri() . '/js/menumaker.js', array( 'jquery' ), wp_get_theme() -> get( 'Version' ), true );
2021-08-01 17:32:46 +00:00
2021-08-01 17:55:17 +00:00
wp_enqueue_script( 'portage-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), wp_get_theme() -> get( 'Version' ), true );
2021-08-01 17:32:46 +00:00
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
}
2021-08-01 17:55:17 +00:00
add_action( 'wp_enqueue_scripts', 'portage_scripts' );
2021-08-01 17:32:46 +00:00
/**
* Enable live changes in the customizer
*/
2021-08-01 17:55:17 +00:00
function portage_customizer_script() {
wp_enqueue_script( 'portage-theme-customizer', get_template_directory_uri() . '/js/customizer.js', array(), wp_get_theme() -> get( 'Version' ), true );
2021-08-01 17:32:46 +00:00
}
2021-08-01 17:55:17 +00:00
add_action( 'customize_preview_init', 'portage_customizer_script' );
2021-08-01 17:32:46 +00:00
// Change "read more" link on excerpts
// codex.wordpress.org/Function_Reference/the_excerpt
2021-08-01 17:55:17 +00:00
function portage_excerpt_more( $more ) {
$text = get_theme_mod( 'portage_readmore', '&hellip;read more&hellip;' );
2021-08-01 17:32:46 +00:00
return ' <a class="excerpt-link" href="' . get_permalink( get_the_ID() ) . '">' . $text . '</a>';
}
2021-08-01 17:55:17 +00:00
add_filter( 'excerpt_more', 'portage_excerpt_more' );
2021-08-01 17:32:46 +00:00
// Add descriptions to main menu
// http://www.wpbeginner.com/wp-themes/how-to-add-menu-descriptions-in-your-wordpress-themes/
/*
2021-08-01 17:55:17 +00:00
class portage_Menu_With_Description extends Walker_Nav_Menu {
2021-08-01 17:32:46 +00:00
function start_el(&$output, $item, $depth=0, $args = array(), $id=0) {
global $wp_query;
$indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
$class_names = $value = '';
$classes = empty( $item->classes ) ? array() : (array) $item->classes;
$class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) );
$class_names = ' class="' . esc_attr( $class_names ) . '"';
$output .= $indent . '<li id="menu-item-'. $item->ID . '"' . $value . $class_names .'>';
$attributes = ! empty( $item->attr_title ) ? ' title="' . esc_attr( $item->attr_title ) .'"' : '';
$attributes .= ! empty( $item->target ) ? ' target="' . esc_attr( $item->target ) .'"' : '';
$attributes .= ! empty( $item->xfn ) ? ' rel="' . esc_attr( $item->xfn ) .'"' : '';
$attributes .= ! empty( $item->url ) ? ' href="' . esc_attr( $item->url ) .'"' : '';
$item_output = $args->before;
$item_output .= '<a'. $attributes .'>';
$item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after;
$item_output .= '<p class="sub">' . $item->description . '</p>';
$item_output .= '</a>';
$item_output .= $args->after;
$output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args, $id );
}
}
*/
/**
* Implement the Custom Header feature.
*/
require get_template_directory() . '/functions/custom-header.php';
/**
* Custom template tags for this theme.
*/
require get_template_directory() . '/functions/template-tags.php';
/**
* Customizer additions.
*/
require get_template_directory() . '/functions/customizer.php';
/**
* Load Jetpack compatibility file.
*/
require get_template_directory() . '/functions/jetpack.php';
/**
* Add our widget areas.
*/
require get_template_directory() . '/functions/widget-areas.php';
/**
* Make our menus mobile.
*/
require get_template_directory() . '/functions/mobile-menus.php';
// Include our update script to update from private repo
2021-08-01 18:05:05 +00:00
/* Deleted for now; get other theme issues working (2021.08.01)
2021-08-01 17:32:46 +00:00
require 'update/puc.php';
$myUpdateChecker = Puc_v4_Factory::buildUpdateChecker(
2021-08-01 17:55:17 +00:00
'http://api.kjodle.net/?action=get_metadata&slug=portage',
2021-08-01 17:32:46 +00:00
__FILE__,
2021-08-01 17:55:17 +00:00
'portage'
2021-08-01 17:32:46 +00:00
);
2021-08-01 18:05:05 +00:00
*/