barebones/functions.php

302 lines
6.5 KiB
PHP
Raw Permalink Normal View History

2012-05-29 23:42:46 +02:00
<?php
2015-10-15 18:24:32 +02:00
/**
* Custom functions / External files
*/
2018-04-17 11:51:22 +02:00
require_once 'includes/custom-functions.php';
2024-01-11 18:09:03 +01:00
/**
* Registering Custom Blocks
*/
function congegni_block_init() {
register_block_type( __DIR__ . '/blocks/deferred-youtube-video' );
}
add_action( 'init', 'congegni_block_init' );
2015-10-15 18:24:32 +02:00
/**
2014-08-07 11:54:20 +02:00
* Add support for useful stuff
*/
2017-06-06 16:23:36 +02:00
2019-01-08 11:52:31 +01:00
if ( function_exists( 'add_theme_support' ) ) {
// Add support for document title tag
2019-01-08 11:52:31 +01:00
add_theme_support( 'title-tag' );
2015-10-15 18:24:32 +02:00
// Add Thumbnail Theme Support
2019-01-08 11:52:31 +01:00
add_theme_support( 'post-thumbnails' );
// add_image_size( 'custom-size', 700, 200, true );
2012-05-29 23:42:46 +02:00
2015-10-15 18:24:32 +02:00
// Add Support for post formats
// add_theme_support( 'post-formats', ['post'] );
2015-10-19 12:54:53 +02:00
// add_post_type_support( 'page', 'excerpt' );
2015-10-15 18:24:32 +02:00
// Localisation Support
2019-01-08 11:52:31 +01:00
load_theme_textdomain( 'barebones', get_template_directory() . '/languages' );
2015-10-15 18:24:32 +02:00
}
2014-08-07 11:54:20 +02:00
2018-04-17 11:51:22 +02:00
/**
* Hide admin bar
2014-08-07 11:54:20 +02:00
*/
2018-04-17 11:51:22 +02:00
2019-01-08 11:52:31 +01:00
add_filter( 'show_admin_bar', '__return_false' );
2018-04-17 11:51:22 +02:00
2013-10-11 18:26:23 +02:00
/**
* Remove junk
*/
2018-04-17 11:51:22 +02:00
remove_action('wp_head', 'rsd_link');
remove_action('wp_head', 'wlwmanifest_link');
remove_action('wp_head', 'wp_generator');
remove_action('wp_head', 'start_post_rel_link');
remove_action('wp_head', 'index_rel_link');
remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');
remove_action('wp_head', 'wp_shortlink_wp_head', 10, 0);
remove_action('wp_head', 'print_emoji_detection_script', 7);
remove_action('wp_print_styles', 'print_emoji_styles');
2018-04-17 11:51:22 +02:00
/**
* Remove comments feed
*
* @return void
*/
2018-04-17 11:51:22 +02:00
function barebones_post_comments_feed_link() {
2013-10-11 18:26:23 +02:00
return;
}
2018-04-17 11:51:22 +02:00
add_filter('post_comments_feed_link', 'barebones_post_comments_feed_link');
2015-10-19 12:54:53 +02:00
2018-04-17 11:51:22 +02:00
/**
* Enqueue scripts
2014-08-07 11:54:20 +02:00
*/
2018-04-17 11:51:22 +02:00
function barebones_enqueue_scripts() {
2023-10-19 10:50:30 +02:00
wp_deregister_script('jquery');
wp_enqueue_style( 'styles', get_stylesheet_directory_uri() . '/style.css?' . filemtime( get_stylesheet_directory() . '/style.css' ) );
2019-01-08 11:52:31 +01:00
wp_enqueue_script( 'scripts', get_stylesheet_directory_uri() . '/js/scripts.min.js?' . filemtime( get_stylesheet_directory() . '/js/scripts.min.js' ), [], null, true );
2013-08-06 10:24:03 +02:00
}
2018-04-17 11:51:22 +02:00
2019-01-08 11:52:31 +01:00
add_action( 'wp_enqueue_scripts', 'barebones_enqueue_scripts' );
2015-10-14 12:10:55 +02:00
2018-04-17 11:51:22 +02:00
2020-02-28 11:18:44 +01:00
/**
* Add async and defer attributes to enqueued scripts
*
* @param string $tag
* @param string $handle
* @param string $src
* @return void
*/
function defer_scripts( $tag, $handle, $src ) {
// The handles of the enqueued scripts we want to defer
$defer_scripts = [
'SCRIPT_ID'
];
// Find scripts in array and defer
if ( in_array( $handle, $defer_scripts ) ) {
return '<script type="text/javascript" src="' . $src . '" defer="defer"></script>' . "\n";
}
return $tag;
}
add_filter( 'script_loader_tag', 'defer_scripts', 10, 3 );
/**
* Remove unnecessary scripts
*
* @return void
*/
function deregister_scripts() {
wp_deregister_script( 'wp-embed' );
}
add_action( 'wp_footer', 'deregister_scripts' );
/**
* Remove unnecessary styles
*
* @return void
*/
function deregister_styles() {
wp_dequeue_style( 'wp-block-library' );
}
add_action( 'wp_print_styles', 'deregister_styles', 100 );
/**
* Register nav menus
*
* @return void
2014-08-07 11:54:20 +02:00
*/
2018-04-17 11:51:22 +02:00
function barebones_register_nav_menus() {
2015-10-14 12:10:55 +02:00
register_nav_menus([
2019-01-08 11:52:31 +01:00
'header' => 'Header',
'footer' => 'Footer',
2015-10-14 12:10:55 +02:00
]);
2014-08-07 11:54:20 +02:00
}
2018-04-17 11:51:22 +02:00
2019-01-08 11:52:31 +01:00
add_action( 'after_setup_theme', 'barebones_register_nav_menus', 0 );
2014-02-21 11:44:42 +01:00
2018-04-17 11:51:22 +02:00
/**
* Nav menu args
*
* @param array $args
* @return void
*/
2018-04-17 11:51:22 +02:00
function barebones_nav_menu_args( $args ) {
$args['container'] = false;
2015-10-14 12:10:55 +02:00
$args['container_class'] = false;
$args['menu_id'] = false;
$args['items_wrap'] = '<ul class="%2$s">%3$s</ul>';
2015-10-15 18:24:32 +02:00
2015-10-14 12:10:55 +02:00
return $args;
2014-02-21 11:44:42 +01:00
}
2018-04-17 11:51:22 +02:00
add_filter('wp_nav_menu_args', 'barebones_nav_menu_args');
2014-08-07 11:54:20 +02:00
2018-04-17 11:51:22 +02:00
/**
* Button Shortcode
*
* @param array $atts
* @param string $content
* @return void
*/
2015-10-15 18:24:32 +02:00
2018-04-17 11:51:22 +02:00
function barebones_button_shortcode( $atts, $content = null ) {
$atts['class'] = isset($atts['class']) ? $atts['class'] : 'btn';
2015-10-14 12:10:55 +02:00
return '<a class="' . $atts['class'] . '" href="' . $atts['link'] . '">' . $content . '</a>';
}
2018-04-17 11:51:22 +02:00
add_shortcode('button', 'barebones_button_shortcode');
2015-10-14 12:10:55 +02:00
2018-04-17 11:51:22 +02:00
/**
* TinyMCE
*
* @param array $buttons
* @return void
*/
2018-04-17 11:51:22 +02:00
function barebones_mce_buttons_2( $buttons ) {
2019-01-08 11:52:31 +01:00
array_unshift( $buttons, 'styleselect' );
2015-10-14 12:10:55 +02:00
$buttons[] = 'hr';
2015-10-15 18:24:32 +02:00
2015-10-14 12:10:55 +02:00
return $buttons;
}
2018-04-17 11:51:22 +02:00
add_filter('mce_buttons_2', 'barebones_mce_buttons_2');
2018-04-17 11:51:22 +02:00
/**
* TinyMCE styling
*
* @param array $settings
* @return void
*/
2018-04-17 11:51:22 +02:00
function barebones_tiny_mce_before_init( $settings ) {
2015-10-14 12:10:55 +02:00
$style_formats = [
[
'title' => 'Text Sizes',
'items' => [
[
'title' => '2XL',
'selector' => 'span, p',
'classes' => 'text-2xl'
],
[
'title' => 'XL',
'selector' => 'span, p',
'classes' => 'text-xl'
],
[
'title' => 'LG',
'selector' => 'span, p',
'classes' => 'text-lg'
],
[
'title' => 'MD',
'selector' => 'span, p',
'classes' => 'text-md'
],
[
'title' => 'SM',
'selector' => 'span, p',
'classes' => 'text-sm'
],
[
'title' => 'XD',
'selector' => 'span, p',
'classes' => 'text-xs'
],
]
]
2015-10-14 12:10:55 +02:00
];
2015-10-15 18:24:32 +02:00
$settings['style_formats'] = json_encode($style_formats);
2015-10-15 18:24:32 +02:00
$settings['style_formats_merge'] = true;
2015-10-14 12:10:55 +02:00
return $settings;
}
2018-04-17 11:51:22 +02:00
add_filter('tiny_mce_before_init', 'barebones_tiny_mce_before_init');
2018-04-17 11:51:22 +02:00
/**
* Get post thumbnail url
*
* @param string $size
* @param boolean $post_id
* @param boolean $icon
* @return void
*/
2018-04-17 11:51:22 +02:00
function get_post_thumbnail_url( $size = 'full', $post_id = false, $icon = false ) {
if ( ! $post_id ) {
2017-06-06 16:23:36 +02:00
$post_id = get_the_ID();
}
2018-04-17 11:51:22 +02:00
$thumb_url_array = wp_get_attachment_image_src(
get_post_thumbnail_id( $post_id ), $size, $icon
);
2017-06-06 16:23:36 +02:00
return $thumb_url_array[0];
}
2018-04-17 11:51:22 +02:00
/**
* Add Front Page edit link to admin Pages menu
*/
2018-04-17 11:51:22 +02:00
function front_page_on_pages_menu() {
2018-04-17 11:51:22 +02:00
global $submenu;
if ( get_option( 'page_on_front' ) ) {
$submenu['edit.php?post_type=page'][501] = array(
2019-01-08 11:52:31 +01:00
__( 'Front Page', 'barebones' ),
2018-04-17 11:51:22 +02:00
'manage_options',
get_edit_post_link( get_option( 'page_on_front' ) )
);
}
}
add_action( 'admin_menu' , 'front_page_on_pages_menu' );