Last active
February 11, 2020 09:42
-
-
Save Fobiya/093d2f0fcffeadeb92125d5cdf8c6c26 to your computer and use it in GitHub Desktop.
(functions.php)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* WordPress (function.php) | |
* @package Fobiya | |
* @subpackage | |
* Template Name: Definitive__Guide | |
* Template Post Type: post, page, product | |
*/ | |
Template Post Type: post, page, product, Landings, landings, landings,l - slag page-attributes | |
add_theme_support('title-tag'); // теперь тайтл управляется самим вп | |
register_nav_menus(array( // Регистрируем 2 меню | |
'top' => 'Верхнее', // Верхнее | |
'bottom' => 'Внизу' // Внизу | |
)); | |
// Version Styles рестартит | |
// Remove WP Version From Styles | |
add_filter( 'style_loader_src', 'sdt_remove_ver_css_js', 9999 ); | |
// Remove WP Version From Scripts | |
add_filter( 'script_loader_src', 'sdt_remove_ver_css_js', 9999 ); | |
// Function to remove version numbers | |
function sdt_remove_ver_css_js( $src ) { | |
if ( strpos( $src, 'ver=' ) ) | |
$src = remove_query_arg( 'ver', $src ); | |
return $src; | |
} | |
// Version Styles рестартит | |
/ -------------------------- SVG UPLOUD --------------------------------------/ | |
function cc_mime_types($mimes) { | |
$mimes['svg'] = 'image/svg+xml'; | |
return $mimes; | |
} | |
add_filter('upload_mimes', 'cc_mime_types'); | |
/ -------------------------- END SVG UPLOUD --------------------------------------/ | |
// type=text/javascript|css NONE | |
add_action('wp_loaded', 'output_buffer_start'); | |
function output_buffer_start() { | |
ob_start("output_callback"); | |
} | |
function output_callback($buffer) { | |
return preg_replace( "%[ ]type=[\'\"]text\/(javascript|css)[\'\"]%", '', $buffer ); | |
} | |
// type=text/javascript|css END NONE | |
//Hide EDITOR! Убирает стандартный редактор | |
add_action('init', 'my_remove_editor_from_post_type'); | |
function my_remove_editor_from_post_type() { | |
remove_post_type_support( 'page', 'editor' ); | |
} | |
//Hide EDITOR! Убирает стандартный редактор | |
if( function_exists('acf_add_options_page') ) { | |
$option_page = acf_add_options_page(array( | |
'page_title' => 'Home', | |
'menu_title' => 'Home', | |
'menu_slug' => 'home', | |
'capability' => 'edit_posts', | |
'redirect' => false | |
)); | |
} | |
if( function_exists('acf_add_options_page') ) { | |
$option_page = acf_add_options_page(array( | |
'page_title' => 'Footer', | |
'menu_title' => 'Footer', | |
'menu_slug' => 'footer', | |
'capability' => 'edit_posts', | |
'redirect' => false | |
)); | |
} | |
if( function_exists('acf_add_options_page') ) { | |
$option_page = acf_add_options_page(array( | |
'page_title' => 'Sconfig Settings', | |
'menu_title' => 'Sconfig Settings', | |
'menu_slug' => 'sconfigsettings', | |
'capability' => 'edit_posts', | |
'redirect' => false | |
)); | |
} | |
if( function_exists('acf_add_options_page') ) { | |
$option_page = acf_add_options_page(array( | |
'page_title' => 'SOLUTIONS PAGES', | |
'menu_title' => 'SOLUTIONS PAGES', | |
'menu_slug' => 'ourpages', | |
'capability' => 'edit_posts', | |
'redirect' => false | |
)); | |
} | |
@ini_set( 'upload_max_size' , '64M' ); | |
@ini_set( 'post_max_size', '64M'); | |
@ini_set( 'max_execution_time', '300' ); | |
/* jquery OFF */ | |
add_action( 'wp_default_scripts', function( $scripts ) { | |
if ( ! empty( $scripts->registered['jquery'] ) ) { | |
$scripts->registered['jquery']->deps = array_diff( $scripts->registered['jquery']->deps, array( 'jquery-migrate' ) ); | |
} | |
} ); | |
/* END jquery OFF */ | |
/* silencer script */ | |
// silencer script | |
function jquery_migrate_silencer() { | |
// create function copy | |
$silencer = '<script>window.console.logger = window.console.log; '; | |
// modify original function to filter and use function copy | |
// bug out if empty to prevent error | |
$silencer .= 'if (tolog == null) {return;} '; | |
// filter messages containing string | |
$silencer .= 'if (tolog.indexOf("Migrate is installed") == -1) {'; | |
$silencer .= '}</script>'; | |
return $silencer; | |
} | |
// for the frontend, use script_loader_tag filter | |
add_filter('script_loader_tag','jquery_migrate_load_silencer', 10, 2); | |
function jquery_migrate_load_silencer($tag, $handle) { | |
if ($handle == 'jquery-migrate') { | |
$silencer = jquery_migrate_silencer(); | |
// prepend to jquery migrate loading | |
$tag = $silencer.$tag; | |
} | |
return $tag; | |
} | |
// for the admin, hook to admin_print_scripts | |
add_action('admin_print_scripts','jquery_migrate_echo_silencer'); | |
function jquery_migrate_echo_silencer() {echo jquery_migrate_silencer();} | |
/* END silencer script */ | |
/* OPTIMIZATION */ | |
/* ==================================== | |
* Plugin Name: Remove script | |
* Description: Убирает скрипты в подвал, удаляет emoji, wlwmanifest_link, wp_shortlink, feed_links, feed_links_extra, rsd_link; удаляет скрипты wp-json | |
* Author: Pavel Denisenko | |
* Author URI: https://hpc.by/wp-content/uploads/files/plugins/Remove%20script%20JSON.zip | |
* Version: 1.0 | |
* ==================================== */ | |
function functionsphp_head_info(){ | |
} | |
//Remove scripts to footer | |
add_action('wp_head', 'functionsphp_head_info'); | |
function footer_enqueue_scripts(){ | |
remove_action('wp_head','wp_print_scripts'); | |
remove_action('wp_head','wp_print_head_scripts',9); | |
remove_action('wp_head','wp_enqueue_scripts',1); | |
add_action('wp_footer','wp_print_scripts',5); | |
add_action('wp_footer','wp_enqueue_scripts',5); | |
add_action('wp_footer','wp_print_head_scripts',5); | |
} | |
add_action('after_setup_theme','footer_enqueue_scripts'); | |
//End | |
//Remove emoji, wlwmanifest,feed | |
remove_action('wp_head', 'print_emoji_detection_script', 7); | |
remove_action('wp_print_styles', 'print_emoji_styles'); | |
remove_action('wp_head', 'wlwmanifest_link'); | |
remove_action('wp_head', 'wp_shortlink_wp_head', 10, 0); | |
remove_action('wp_head', 'feed_links_extra', 3); | |
remove_action('wp_head', 'rsd_link'); | |
remove_action('wp_head', 'feed_links', 2); | |
remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0 ); | |
//End | |
//Remove JSON API links in header html | |
remove_action( 'wp_head', 'rest_output_link_wp_head'); | |
remove_action( 'wp_head', 'wp_oembed_add_discovery_links'); | |
remove_action( 'template_redirect', 'rest_output_link_header', 11, 0 ); | |
//End | |
/// Оптимизатор remove_styles styles | |
function remove_styles () { | |
wp_deregister_style ('main'); | |
wp_deregister_style ('ioniconsSLID'); | |
wp_deregister_style ('slickSLID'); | |
} | |
add_action ('wp_print_styles','remove_styles',100); | |
/// END Оптимизатор remove_styles styles | |
/* END OPTIMIZATION */ | |
https://support.advancedcustomfields.com/forums/topic/options-page-polylang/ | |
Poly leng languageslanguageslanguages | |
if ( function_exists( 'acf_add_options_page' ) ) { | |
// Main Theme Settings Page | |
$parent = acf_add_options_page( array( | |
'page_title' => 'Theme General Settings', | |
'menu_title' => 'Theme Settings', | |
'redirect' => 'Theme Settings', | |
) ); | |
// | |
// Global Options | |
// Same options on all languages. e.g., social profiles links | |
// | |
acf_add_options_sub_page( array( | |
'page_title' => 'Global Options', | |
'menu_title' => __('Global Options', 'text-domain'), | |
'menu_slug' => "acf-options", | |
'parent' => $parent['menu_slug'] | |
) ); | |
// | |
// Language Specific Options | |
// Translatable options specific languages. e.g., social profiles links | |
// | |
$languages = array( 'it', 'en' ); | |
foreach ( $languages as $lang ) { | |
acf_add_options_sub_page( array( | |
'page_title' => 'Options (' . strtoupper( $lang ) . ')', | |
'menu_title' => __('Options (' . strtoupper( $lang ) . ')', 'text-domain'), | |
'menu_slug' => "options-${lang}", | |
'post_id' => $lang, | |
'parent' => $parent['menu_slug'] | |
) ); | |
} | |
} | |
the_field('my_field_name', 'en'); | |
or even: | |
the_field('my_field_name', pll_current_language('slug')); | |
if( function_exists('acf_add_options_page') ) { | |
// Language Specific Options | |
// Translatable options specific languages. e.g., social profiles links | |
// | |
$languages = array( 'en', 'es' ); | |
foreach ( $languages as $lang ) { | |
acf_add_options_page( array( | |
'page_title' => 'Site Options (' . strtoupper( $lang ) . ')', | |
'menu_title' => __('Site Options (' . strtoupper( $lang ) . ')', 'text-domain'), | |
'menu_slug' => "site-options-${lang}", | |
'post_id' => $lang | |
) ); | |
} | |
} | |
the_field('YOUR_FIELD',pll_current_language('slug')); | |
the_field('YOUR_FIELD','option'); | |
function template_variables( $atts ){ | |
return get_permalink( pll_get_post( get_field('login_page', 'options'))); | |
} | |
add_shortcode( 'login_page', 'template_variables' ); | |
[login_page] | |
add_filter('acf/format_value/type=textarea', 'do_shortcode'); | |
add_filter('acf/format_value/type=text', 'do_shortcode'); | |
add_filter('acf/format_value/type=email', 'do_shortcode'); | |
add_filter('acf/format_value/type=url', 'do_shortcode'); | |
add_filter('acf/format_value/type=number', 'do_shortcode'); | |
add_filter('acf/format_value/type=image', 'do_shortcode'); | |
add_filter('acf/format_value/type=link', 'do_shortcode'); | |
function template_variables(){ | |
return get_permalink( pll_get_post( get_field('login_page', 'options'))); | |
} | |
add_shortcode( 'login_page', 'template_variables' ); | |
function dark__logo__a() { | |
return '<img src="'. get_field('dark_logo', 'options').'"/>'; | |
} | |
add_shortcode( 'dark_logo', 'dark__logo__a' ); | |
polyleng | |
function leng__inform(){ | |
return pll_e( 'emmm','emmm','emmm','emmm','emmm'); | |
} | |
add_shortcode( 'emmm', 'leng__inform' ); | |
function brand_config($atts){ | |
switch ($atts['var']) { | |
case "email": | |
return get_field('brand_email', 'options'); | |
//return '<a href="mailto:'. get_field('brand_email', 'options').'">'. get_field('brand_email', 'options').'</a>'; | |
break; | |
case "email_link": | |
return '<a href="mailto:'. get_field('brand_email', 'options').'">'. get_field('brand_email', 'options').'</a>'; | |
break; | |
case "phone": | |
return get_field('brand_phone', 'options'); | |
break; | |
case "login_url": | |
return get_permalink( pll_get_post( get_field('login_page', 'options'))); | |
break; | |
case "registration_url": | |
return get_permalink( pll_get_post( get_field('registration_page', 'options'))); | |
break; | |
case "contact_us_page_url": | |
return get_permalink( pll_get_post( get_field('contact_us_page_url', 'options'))); | |
break; | |
default: | |
return get_permalink( pll_get_post( get_field('login_page', 'options'))); | |
} | |
} | |
add_shortcode( 'brand', 'brand_config' ); | |
//SVG UPLOAD SUPPORT | |
function cc_mime_types($mimes) { | |
$mimes['svg'] = 'image/svg+xml'; | |
return $mimes; | |
} | |
add_filter('upload_mimes', 'cc_mime_types'); | |
wp_enqueue_style( 'main-css', get_template_directory_uri() . '/css/main.css', '', filemtime(get_stylesheet_directory() .'/css/main.css'), 'all' ); | |
/-------------------------------------------------------- register_taxonomy register_post_type ---------------/ | |
register_taxonomy('category_blog', array('blog'), array( | |
'hierarchical' => true, | |
'labels' => array( | |
'name' => __('Categories blog', 'taxonomy general name'), | |
'singular_name' => __('Category blog', 'taxonomy singular name'), | |
'search_items' => __('Search Topics'), | |
'all_items' => __('All Topics'), | |
'parent_item' => __('Parent Topic'), | |
'parent_item_colon' => __('Parent Topic:'), | |
'edit_item' => __('Edit Topic'), | |
'update_item' => __('Update Topic'), | |
'add_new_item' => __('Add New Topic'), | |
'new_item_name' => __('New Topic Name'), | |
'menu_name' => __('Categories blog'), | |
), | |
'show_ui' => true, | |
'show_admin_column' => true, | |
'query_var' => true, | |
'rewrite' => array('slug' => 'blog'), | |
)); | |
function create_blog() | |
{ | |
register_post_type('blog', array( | |
'labels' => array( | |
'name' => __('Blog', 'marginelite-admin'), | |
'singular_name' => __('blog', 'marginelite-admin'), | |
'add_new' => __('Add post blog', 'marginelite-admin'), | |
'add_new_item' => __('Add post blog', 'marginelite-admin'), | |
'edit' => __('Edit post blog', 'marginelite-admin'), | |
'edit_item' => __('Edit post blog', 'marginelite-admin'), | |
'new_item' => __('New post blog', 'marginelite-admin'), | |
'all_items' => __('All post blog', 'marginelite-admin'), | |
'view' => __('View post blog', 'marginelite-admin'), | |
'view_item' => __('View post blog', 'marginelite-admin'), | |
'search_items' => __('Search post blog', 'marginelite-admin'), | |
'not_found' => __('Webinars not found', 'marginelite-admin'), | |
), | |
'public' => true, // show in admin panel? | |
'menu_position' => 22, | |
'supports' => array('title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments', 'page-attributes'), | |
'taxonomies' => array('category_blog'), | |
'has_archive' => false, | |
'capability_type' => 'post', | |
'menu_icon' => 'dashicons-portfolio', | |
'rewrite' => array('slug' => 'blog'), | |
)); | |
} | |
add_action('init', 'create_blog'); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment