/home/bdqbpbxa/demo-subdomains/sparkskyiv.goodface.com.ua/wp-content/themes/sparks/functions.php
<?php
/**
* sparks functions and definitions
*
* @link https://developer.wordpress.org/themes/basics/theme-functions/
*
* @package sparks
*/
if ( ! function_exists( 'sparks_setup' ) ) :
/**
* 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.
*/
function sparks_setup() {
/*
* Make theme available for translation.
* Translations can be filed in the /languages/ directory.
* If you're building a theme based on sparks, use a find and replace
* to change 'sparks' to the name of your theme in all the template files.
*/
load_theme_textdomain( 'sparks', get_template_directory() . '/languages' );
// 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 https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/
*/
add_theme_support( 'post-thumbnails' );
// This theme uses wp_nav_menu() in one location.
register_nav_menus( array(
'menu-1' => esc_html__( 'Primary', 'sparks' ),
) );
/*
* 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',
) );
// Set up the WordPress core custom background feature.
add_theme_support( 'custom-background', apply_filters( 'sparks_custom_background_args', array(
'default-color' => 'ffffff',
'default-image' => '',
) ) );
// Add theme support for selective refresh for widgets.
add_theme_support( 'customize-selective-refresh-widgets' );
/**
* Add support for core custom logo.
*
* @link https://codex.wordpress.org/Theme_Logo
*/
add_theme_support( 'custom-logo', array(
'height' => 250,
'width' => 250,
'flex-width' => true,
'flex-height' => true,
) );
}
endif;
add_action( 'after_setup_theme', 'sparks_setup' );
/**
* 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
*/
function sparks_content_width() {
// This variable is intended to be overruled from themes.
// Open WPCS issue: {@link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/1043}.
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
$GLOBALS['content_width'] = apply_filters( 'sparks_content_width', 640 );
}
add_action( 'after_setup_theme', 'sparks_content_width', 0 );
/**
* Register widget area.
*
* @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
*/
function sparks_widgets_init() {
register_sidebar(
array(
'id' => 'lang_switcher', // уникальный id
'name' => 'Переключатель языка', // название сайдбара
'description' => '', // описание
'before_widget' => '', // по умолчанию виджеты выводятся <li>-списком
'after_widget' => '',
'before_title' => '', // по умолчанию заголовки виджетов в <h2>
'after_title' => ''
)
);
}
add_action( 'widgets_init', 'sparks_widgets_init' );
/**
* Enqueue scripts and styles.
*/
function sparks_scripts() {
wp_enqueue_style( 'sparks-slickcss', get_template_directory_uri() . '/css/slick.min.css', array(), 'v4' );
wp_enqueue_style( 'sparks-generalcss', get_template_directory_uri() . '/css/style.css', array(), 'v4' );
wp_enqueue_style( 'sparks-addcss', get_template_directory_uri() . '/css/main.css', array(), 'v4' );
wp_enqueue_style( 'sparks-style', get_stylesheet_uri() );
wp_enqueue_script( 'sparks-tilt', get_template_directory_uri() . '/js/tilt.min.js', array('jquery'), 'v4', true );
wp_enqueue_script( 'sparks-slickjs', get_template_directory_uri() . '/js/slick.min.js', array('jquery'), 'v4', true );
wp_enqueue_script( 'sparks-mainjs', get_template_directory_uri() . '/js/main.js', array('jquery'), 'v4', true );
wp_enqueue_script( 'sparks-addjs', get_template_directory_uri() . '/js/script.js', array('jquery'), 'v4', true );
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
}
add_action( 'wp_enqueue_scripts', 'sparks_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';
/**
* Functions which enhance the theme by hooking into WordPress.
*/
require get_template_directory() . '/inc/template-functions.php';
/**
* Customizer additions.
*/
require get_template_directory() . '/inc/customizer.php';
/**
* Load Jetpack compatibility file.
*/
if ( defined( 'JETPACK__VERSION' ) ) {
require get_template_directory() . '/inc/jetpack.php';
}
if( function_exists('acf_add_options_page') ) {
acf_add_options_page(array(
'page_title' => 'Глобальные настройки сайта',
'menu_title' => 'Настройки сайта',
'menu_slug' => 'site-options',
'capability' => 'edit_posts',
'redirect' => false
));
}
function true_loadmore_scripts() {
wp_enqueue_script( 'true_loadmore', get_template_directory_uri() . '/js/loadmore.js', array('jquery'), '20151215', true );
}
add_action( 'wp_enqueue_scripts', 'true_loadmore_scripts' );
function true_load_posts(){
// $args = unserialize( stripslashes( $_POST['query'] ) );
$args['paged'] = $_POST['page'];
$args['posts_per_page'] = 6;
$args['post_status'] = 'publish';
// обычно лучше использовать WP_Query, но не здесь
query_posts( $args );
// если посты есть
if( have_posts() ) :
// запускаем цикл
while( have_posts() ): the_post();
?>
<div class="news-item">
<div class="news-image">
<a href="<?php the_permalink(); ?>"><img src="<?php echo get_the_post_thumbnail_url(); ?>" alt=""></a>
</div>
<div class="news-date"><?php the_field('event_date'); ?></div>
<div class="news-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></div>
<div class="news-desc"><?php the_excerpt(); ?></div>
<div class="news-details">
<a href="<?php the_permalink(); ?>" class="news-details-link"><?php pll_e('Читати повністю'); ?></a>
</div>
</div>
<?php
endwhile;
endif;
die();
}
add_action('wp_ajax_loadmore', 'true_load_posts');
add_action('wp_ajax_nopriv_loadmore', 'true_load_posts');
function add_post_gallery( $atts ){
$html = '';
$id = get_the_ID();
$gallery = get_field('post_gallery',$id);
if($gallery) {
$html .= '<p class="slider-margin"></p><div class="article-images">';
foreach($gallery as $image) {
$html .= '<div class="article-slide-image"><img src="'.$image['url'].'"/></div>';
}
$html .= '</div><div class="article-inner">';
}
return $html;
}
add_shortcode( 'custom_gallery', 'add_post_gallery' );
add_action( 'edit_form_after_title', 'myprefix_edit_form_after_title' );
function myprefix_edit_form_after_title() {
global $pagenow;
if ( 'post.php' === $pagenow && isset($_GET['post']) && 'post' === get_post_type( $_GET['post'] ) ) {
echo '<p><b>[custom_gallery]</b> - вставьте этот шорткод в место где вы хотите разместить слайдер с картинками</p>';
}
}
add_action('admin_head', 'remove_content_editor');
/**
* Remove the content editor from ALL pages
*/
function remove_content_editor()
{
remove_post_type_support('page', 'editor');
}
// Move Yoast to bottom
function yoasttobottom() {
return 'low';
}
add_filter( 'wpseo_metabox_prio', 'yoasttobottom');
function add_specific_menu_location_atts( $atts, $item, $args ) {
// check if the item is in the primary menu
if( mb_substr($atts['href'],0,1) == '#' && is_front_page()) {
// add the desired attributes:
$atts['class'] = 'anchor';
}
return $atts;
}
add_filter( 'nav_menu_link_attributes', 'add_specific_menu_location_atts', 10, 3 );
// add_action('init', function() {
// pll_register_string('mytheme-hello', 'Читати повністю');
// pll_register_string('show-more', 'Показати більше новин');
// pll_register_string('order-table', 'Забронировать столик');
// pll_register_string('back-btn', 'Повернутися назад');
// pll_register_string('news', 'Новини');
// });
add_filter( 'get_custom_logo', 'change_logo_class' );
function change_logo_class( $html ) {
$html = str_replace( 'custom-logo-link', 'logo', $html );
return $html;
}