__( 'Primary Menu', 'forever' ), ) ); /** * Add support for the Aside and Gallery Post Formats */ add_theme_support( 'post-formats', array( 'gallery', 'image', 'status', 'quote' ) ); /** * Enqueue styles. */ function forever_styles() { wp_enqueue_style( 'forever-style', get_stylesheet_uri() ); } add_action( 'wp_enqueue_scripts', 'forever_styles' ); /** * Enqueue Fonts. */ function forever_fonts() { wp_enqueue_style( 'raleway', "https://fonts.googleapis.com/css?family=Raleway:100" ); } add_action( 'wp_enqueue_scripts', 'forever_fonts' ); /** * Enqueue scripts */ function forever_scripts() { // enqueue comment reply script if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) { wp_enqueue_script( 'comment-reply' ); } // enqueue masonry for the guestbook page template if ( is_page_template( 'guestbook.php') ) { wp_enqueue_script( 'jquery' ); wp_enqueue_script( 'masonry' ); wp_enqueue_script( 'guestbook', get_template_directory_uri() . '/js/guestbook.js', array( 'jquery', 'masonry' ), '28-12-2011', true ); } } add_action( 'wp_enqueue_scripts', 'forever_scripts' ); /** * This theme uses Featured Images (also known as post thumbnails) */ add_theme_support( 'post-thumbnails' ); /* * Register custom image sizes. */ forever_add_image_sizes(); } endif; // forever_setup /** * Tell WordPress to run forever_setup() when the 'after_setup_theme' hook is run. */ add_action( 'after_setup_theme', 'forever_setup' ); /** * Maybe enable theme options. * * Theme options are enabled by default in Forever. * Child themes and plugins may disable all * options by using the following code before the * "after_theme_setup" action fires at priority 10. * * add_filter( 'forever-enable-theme-options', '__return_false' ); * * @since Forever 1.1 */ function forever_maybe_enable_theme_options() { if ( apply_filters( 'forever-enable-theme-options', true ) ) require( get_template_directory() . '/inc/theme-options.php' ); } /** * Add image sizes. * * @since Forever 1.1 */ function forever_get_image_sizes() { $defaults = array( 'large-feature' => array( 888, 355, true ), 'small-feature' => array( 195, 124, true ), ); $sizes = apply_filters( 'forever-image-sizes', $defaults ); return $sizes; } /** * Add image sizes. * * @uses forever_get_image_sizes(). * @since Forever 1.1 */ function forever_add_image_sizes() { $sizes = forever_get_image_sizes(); foreach ( (array) $sizes as $name => $size ) { add_image_size( $name, $size[0], $size[1], $size[2] ); } } /** * Enables child themes and plugins to set a * custom image size for post thumbnail. * * @since Forever 1.1 */ function forever_get_post_thumbnail_size() { return apply_filters( 'forever-post-thumbnail-size', 'thumbnail' ); } /** * Setup the WordPress core custom background feature. * * Hooks into the after_setup_theme action. */ function forever_register_custom_background() { add_theme_support( 'custom-background', apply_filters( 'forever_custom_background_args', array( 'default-color' => 'fff', 'default-image' => get_template_directory_uri() . '/images/body-bg.png', ) ) ); } add_action( 'after_setup_theme', 'forever_register_custom_background' ); /** * Sets the post excerpt length to 40 words. */ function forever_excerpt_length( $length ) { return 40; } add_filter( 'excerpt_length', 'forever_excerpt_length' ); /** * Returns a "Continue reading" link for excerpts */ function forever_continue_reading_link() { return ' ' . __( 'Continue reading ', 'forever' ) . ''; } /** * Replaces "[...]" (appended to automatically generated excerpts) with an ellipsis and forever_continue_reading_link(). */ function forever_auto_excerpt_more( $more ) { return ' …' . forever_continue_reading_link(); } add_filter( 'excerpt_more', 'forever_auto_excerpt_more' ); /** * Adds a pretty "Continue Reading" link to custom post excerpts. */ function forever_custom_excerpt_more( $output ) { if ( has_excerpt() && ! is_attachment() ) { $output .= forever_continue_reading_link(); } return $output; } add_filter( 'get_the_excerpt', 'forever_custom_excerpt_more' ); /** * Get our wp_nav_menu() fallback, wp_page_menu(), to show a home link. */ function forever_page_menu_args( $args ) { $args['show_home'] = true; return $args; } add_filter( 'wp_page_menu_args', 'forever_page_menu_args' ); /** * Register widgetized area and update sidebar with default widgets */ function forever_widgets_init() { register_sidebar( array( 'name' => __( 'Sidebar', 'forever' ), 'id' => 'sidebar-1', 'before_widget' => '", 'before_title' => '

', 'after_title' => '

', ) ); register_sidebar( array( 'name' => __( 'Footer Widget Area One', 'forever' ), 'description' => __( 'An optional footer widget area.', 'forever' ), 'id' => 'sidebar-2', 'before_widget' => '", 'before_title' => '

', 'after_title' => '

', ) ); register_sidebar( array( 'name' => __( 'Footer Widget Area Two', 'forever' ), 'description' => __( 'An optional footer widget area.', 'forever' ), 'id' => 'sidebar-3', 'before_widget' => '", 'before_title' => '

', 'after_title' => '

', ) ); register_sidebar( array( 'name' => __( 'Footer Widget Area Three', 'forever' ), 'description' => __( 'An optional footer widget area.', 'forever' ), 'id' => 'sidebar-4', 'before_widget' => '", 'before_title' => '

', 'after_title' => '

', ) ); register_sidebar( array( 'name' => __( 'Footer Widget Area Four', 'forever' ), 'description' => __( 'An optional footer widget area.', 'forever' ), 'id' => 'sidebar-5', 'before_widget' => '", 'before_title' => '

', 'after_title' => '

', ) ); } add_action( 'widgets_init', 'forever_widgets_init' ); if ( ! function_exists( 'forever_content_nav' ) ): /** * Display navigation to next/previous pages when applicable * * @since Forever 1.0 */ function forever_content_nav( $nav_id ) { global $wp_query; ?> comment_type ) : case 'pingback' : case 'trackback' : ?>
  • id="li-comment-">
    comment_parent ) $comment_avatar_size = 28; echo get_avatar( $comment, $comment_avatar_size ); ?>
    comment_approved == '0' ) : ?>
    $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
    Posted on by ', 'forever' ), esc_url( get_permalink() ), esc_attr( get_the_time() ), esc_attr( get_the_date( 'c' ) ), esc_html( get_the_date() ), esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ), esc_attr( sprintf( __( 'View all posts by %s', 'forever' ), get_the_author() ) ), esc_html( get_the_author() ) ); } endif; /** * Adds custom classes to the array of body classes. * * @since Forever 1.0 */ function forever_body_classes( $classes ) { // Adds a class of single-author to blogs with only 1 published author if ( ! is_multi_author() ) { $classes[] = 'single-author'; } // Adds a class of index to views that are not posts or pages or search if ( ! is_singular() && ! is_search() ) { $classes[] = 'indexed'; } return $classes; } add_filter( 'body_class', 'forever_body_classes' ); /** * Count the number of footer sidebars to enable dynamic classes for the footer */ function forever_footer_sidebar_class() { $count = 0; if ( is_active_sidebar( 'sidebar-2' ) ) $count++; if ( is_active_sidebar( 'sidebar-3' ) ) $count++; if ( is_active_sidebar( 'sidebar-4' ) ) $count++; if ( is_active_sidebar( 'sidebar-5' ) ) $count++; $class = ''; switch ( $count ) { case '1': $class = 'one'; break; case '2': $class = 'two'; break; case '3': $class = 'three'; break; case '4': $class = 'four'; break; } if ( $class ) echo 'class="' . $class . '"'; } /** * Returns true if a blog has more than 1 category * * @since Forever 1.0 */ function forever_categorized_blog() { if ( false === ( $all_the_cool_cats = get_transient( 'all_the_cool_cats' ) ) ) { // Create an array of all the categories that are attached to posts $all_the_cool_cats = get_categories( array( 'hide_empty' => 1, ) ); // Count the number of categories that are attached to the posts $all_the_cool_cats = is_countable( $all_the_cool_cats ) ? count( $all_the_cool_cats ) : 0; set_transient( 'all_the_cool_cats', $all_the_cool_cats ); } if ( '1' != $all_the_cool_cats ) { // This blog has more than 1 category so forever_categorized_blog should return true return true; } else { // This blog has only 1 category so forever_categorized_blog should return false return false; } } /** * Flush out the transients used in forever_categorized_blog * * @since Forever 1.0 */ function forever_category_transient_flusher() { // Like, beat it. Dig? delete_transient( 'all_the_cool_cats' ); } add_action( 'edit_category', 'forever_category_transient_flusher' ); add_action( 'save_post', 'forever_category_transient_flusher' ); /** * Filter in a link to a content ID attribute for the next/previous image links on image attachment pages */ function forever_enhanced_image_navigation( $url ) { global $post, $wp_rewrite; // Bail if there is no $post, like in the dashboard recent comments widget. if ( ! isset( $post ) ) return $url; $id = (int) $post->ID; $object = get_post( $id ); if ( wp_attachment_is_image( $post->ID ) && ( $wp_rewrite->using_permalinks() && ( $object->post_parent > 0 ) && ( $object->post_parent != $id ) ) ) $url = $url . '#main'; return $url; } add_filter( 'attachment_link', 'forever_enhanced_image_navigation' ); /** * Filter the home page posts, and remove any featured post IDs from it. Hooked * onto the 'pre_get_posts' action, this changes the parameters of the query * before it gets any posts. * * @global array $featured_post_id * @param WP_Query $query * @return WP_Query Possibly modified WP_query */ function forever_home_posts( $query = false ) { // Bail if not home, not a query, not main query. if ( ! is_home() || ! is_a( $query, 'WP_Query' ) || ! $query->is_main_query() ) return $query; $featured = forever_featured_posts(); $recent = apply_filters( 'forever-recent-posts', false ); // Bail if no featured posts. if ( ! $featured && ! $recent ) return $query; // Exclude featured posts from the main query. $query->query_vars['post__not_in'] = array_merge( (array) $featured, (array) $recent ); return $query; } add_action( 'pre_get_posts', 'forever_home_posts' ); /** * Test to see if any posts meet our conditions for featuring posts. * * @return mixed Array of featured post ids on success, false on failure. */ function forever_featured_posts() { $featured_post_ids = get_transient( 'featured_post_ids' ); // Return cached results. if ( ! empty( $featured_post_ids ) ) return $featured_post_ids; $sticky_posts = get_option( 'sticky_posts' ); // Proceed only if sticky posts exist. if ( empty( $sticky_posts ) || ! is_array( $sticky_posts ) ) return false; // The Featured Posts query. $featured = new WP_Query( array( 'post__in' => $sticky_posts, 'post_status' => 'publish', 'no_found_rows' => true, 'ignore_sticky_posts' => 1, 'posts_per_page' => 50, ) ); // Proceed only if published posts exist. if ( ! $featured->have_posts() ) return false; $sizes = forever_get_image_sizes(); $min_width = 888; if ( isset( $sizes['large-feature'][0] ) ) $min_width = $sizes['large-feature'][0]; while ( $featured->have_posts() ) { $featured->the_post(); $image = wp_get_attachment_image_src( get_post_thumbnail_id( $featured->post->ID ), 'large-feature' ); if ( $image && isset( $image[1] ) && $min_width <= $image[1] ) { $featured_post_ids[] = $featured->post->ID; } } set_transient( 'featured_post_ids', $featured_post_ids ); wp_reset_postdata(); return $featured_post_ids; } /** * Flush out the transients used in forever_featured_posts() * * Hooks into the "save_post" and "update_option_sticky_posts" actions. * * Vvwooshh! */ function forever_featured_post_checker_flusher() { delete_transient( 'featured_post_ids' ); } add_action( 'update_option_sticky_posts', 'forever_featured_post_checker_flusher' ); add_action( 'save_post', 'forever_featured_post_checker_flusher' ); require_once __DIR__ . '/inc/custom-header.php' ; /** * Filters wp_title to print a neat tag based on what is being viewed. * * @since Forever 1.1 */ function forever_wp_title( $title, $sep ) { global $page, $paged; if ( is_feed() ) return $title; // Add the blog name $title .= get_bloginfo( 'name' ); // Add the blog description for the home/front page. $site_description = get_bloginfo( 'description', 'display' ); if ( $site_description && ( is_home() || is_front_page() ) ) $title .= " $sep $site_description"; // Add a page number if necessary: if ( $paged >= 2 || $page >= 2 ) $title .= " $sep " . sprintf( __( 'Page %s', 'forever' ), max( $paged, $page ) ); return $title; } add_filter( 'wp_title', 'forever_wp_title', 10, 2 ); /* * Remove widont filter if Posts in Columns options is active * * @since Forever 1.2.2 */ function forever_wido() { if ( ! function_exists( 'forever_get_theme_options' ) ) { return false; } $options = forever_get_theme_options(); if ( 'on' != $options['posts_in_columns'] ) { return false; } remove_filter( 'the_title', 'widont' ); } add_action( 'init', 'forever_wido' ); /** * Show a nice admin message saying Forever has an update in the form of Toujours. */ function forever_change_notice() { $theme_link = admin_url( 'themes.php?s=toujours' ); ?> <div id="message" class="notice notice-info is-dismissible"> <p style="line-height: 1.5em;">Howdy! Your current theme, <em>Forever</em>, has seen an update in the form of a brand new theme, <em><a href="<?php echo esc_url( $theme_link ); ?>">Toujours</a></em>. For more information, check out <a href="https://en.blog.wordpress.com/2016/01/14/toujours">our blog post introducing <em>Toujours</em> to the world</a>.</p> </div> <?php } remove_action( 'admin_notices', 'show_tip' ); add_action( 'admin_notices', 'forever_change_notice' );