Agregar estructura completa del tema APUS con Bootstrap 5 y optimizaciones de rendimiento
Se implementa tema WordPress personalizado para Análisis de Precios Unitarios con funcionalidades avanzadas: - Sistema de templates (front-page, single, archive, page, 404, search) - Integración de Bootstrap 5.3.8 con estructura modular de assets - Panel de opciones del tema con Customizer API - Optimizaciones de rendimiento (Critical CSS, Image Optimization, Performance) - Funcionalidades SEO y compatibilidad con Rank Math - Sistema de posts relacionados y tabla de contenidos - Badge de categorías y manejo de AdSense diferido - Tipografías Google Fonts configurables - Documentación completa del tema y guías de uso 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
160
wp-content/themes/apus-theme/inc/customizer-fonts.php
Normal file
160
wp-content/themes/apus-theme/inc/customizer-fonts.php
Normal file
@@ -0,0 +1,160 @@
|
||||
<?php
|
||||
/**
|
||||
* Font Options for Theme Customizer
|
||||
*
|
||||
* @package Apus_Theme
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
||||
// Exit if accessed directly
|
||||
if (!defined('ABSPATH')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register font settings in the Customizer
|
||||
*/
|
||||
function apus_customize_register_fonts($wp_customize) {
|
||||
|
||||
// Add Typography Section
|
||||
$wp_customize->add_section('apus_typography', array(
|
||||
'title' => __('Typography', 'apus-theme'),
|
||||
'description' => __('Configure font settings for your site.', 'apus-theme'),
|
||||
'priority' => 30,
|
||||
));
|
||||
|
||||
// Setting: Use Custom Fonts
|
||||
$wp_customize->add_setting('apus_use_custom_fonts', array(
|
||||
'default' => false,
|
||||
'sanitize_callback' => 'apus_sanitize_checkbox',
|
||||
'transport' => 'refresh',
|
||||
));
|
||||
|
||||
$wp_customize->add_control('apus_use_custom_fonts', array(
|
||||
'label' => __('Use Custom Fonts', 'apus-theme'),
|
||||
'description' => __('Enable custom fonts instead of system fonts. System fonts load faster and improve Core Web Vitals.', 'apus-theme'),
|
||||
'section' => 'apus_typography',
|
||||
'type' => 'checkbox',
|
||||
));
|
||||
|
||||
// Setting: Font Loading Strategy (only if custom fonts enabled)
|
||||
$wp_customize->add_setting('apus_font_display', array(
|
||||
'default' => 'swap',
|
||||
'sanitize_callback' => 'apus_sanitize_select',
|
||||
'transport' => 'refresh',
|
||||
));
|
||||
|
||||
$wp_customize->add_control('apus_font_display', array(
|
||||
'label' => __('Font Display Strategy', 'apus-theme'),
|
||||
'description' => __('Controls how fonts are displayed during loading. "swap" is recommended for best performance.', 'apus-theme'),
|
||||
'section' => 'apus_typography',
|
||||
'type' => 'select',
|
||||
'choices' => array(
|
||||
'auto' => __('Auto', 'apus-theme'),
|
||||
'block' => __('Block', 'apus-theme'),
|
||||
'swap' => __('Swap (Recommended)', 'apus-theme'),
|
||||
'fallback' => __('Fallback', 'apus-theme'),
|
||||
'optional' => __('Optional', 'apus-theme'),
|
||||
),
|
||||
'active_callback' => 'apus_is_custom_fonts_enabled',
|
||||
));
|
||||
|
||||
// Setting: Preload Fonts
|
||||
$wp_customize->add_setting('apus_preload_fonts', array(
|
||||
'default' => true,
|
||||
'sanitize_callback' => 'apus_sanitize_checkbox',
|
||||
'transport' => 'refresh',
|
||||
));
|
||||
|
||||
$wp_customize->add_control('apus_preload_fonts', array(
|
||||
'label' => __('Preload Font Files', 'apus-theme'),
|
||||
'description' => __('Preload critical font files for faster rendering. Recommended for better LCP scores.', 'apus-theme'),
|
||||
'section' => 'apus_typography',
|
||||
'type' => 'checkbox',
|
||||
'active_callback' => 'apus_is_custom_fonts_enabled',
|
||||
));
|
||||
}
|
||||
|
||||
add_action('customize_register', 'apus_customize_register_fonts');
|
||||
|
||||
/**
|
||||
* Sanitize checkbox
|
||||
*/
|
||||
function apus_sanitize_checkbox($input) {
|
||||
return (isset($input) && true === $input) ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitize select
|
||||
*/
|
||||
function apus_sanitize_select($input, $setting) {
|
||||
$choices = $setting->manager->get_control($setting->id)->choices;
|
||||
return (array_key_exists($input, $choices) ? $input : $setting->default);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if custom fonts are enabled
|
||||
*/
|
||||
function apus_is_custom_fonts_enabled() {
|
||||
return get_theme_mod('apus_use_custom_fonts', false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add body class based on font settings
|
||||
*/
|
||||
function apus_font_body_class($classes) {
|
||||
if (apus_is_custom_fonts_enabled()) {
|
||||
$classes[] = 'use-custom-fonts';
|
||||
} else {
|
||||
$classes[] = 'use-system-fonts';
|
||||
}
|
||||
return $classes;
|
||||
}
|
||||
|
||||
add_filter('body_class', 'apus_font_body_class');
|
||||
|
||||
/**
|
||||
* Add preload links for custom fonts
|
||||
*/
|
||||
function apus_preload_custom_fonts() {
|
||||
// Only preload if custom fonts are enabled and preload is enabled
|
||||
if (!apus_is_custom_fonts_enabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!get_theme_mod('apus_preload_fonts', true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Example preload links - uncomment and modify when you have custom font files
|
||||
/*
|
||||
?>
|
||||
<link rel="preload" href="<?php echo esc_url(get_template_directory_uri() . '/assets/fonts/CustomSans-Regular.woff2'); ?>" as="font" type="font/woff2" crossorigin>
|
||||
<link rel="preload" href="<?php echo esc_url(get_template_directory_uri() . '/assets/fonts/CustomSans-Bold.woff2'); ?>" as="font" type="font/woff2" crossorigin>
|
||||
<?php
|
||||
*/
|
||||
}
|
||||
|
||||
add_action('wp_head', 'apus_preload_custom_fonts', 1);
|
||||
|
||||
/**
|
||||
* Output inline CSS for font display strategy
|
||||
*/
|
||||
function apus_output_font_display_css() {
|
||||
if (!apus_is_custom_fonts_enabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$font_display = get_theme_mod('apus_font_display', 'swap');
|
||||
|
||||
// This would be used if you have actual @font-face declarations
|
||||
// For now, it's just a placeholder for future implementation
|
||||
?>
|
||||
<style id="apus-font-display-strategy">
|
||||
/* Font display strategy: <?php echo esc_attr($font_display); ?> */
|
||||
/* This would contain dynamic @font-face rules when custom fonts are added */
|
||||
</style>
|
||||
<?php
|
||||
}
|
||||
|
||||
add_action('wp_head', 'apus_output_font_display_css', 5);
|
||||
Reference in New Issue
Block a user