aboutsummaryrefslogtreecommitdiffstats
path: root/functions.php
blob: f330eb915fe2121be708aca6cf93090104104e95 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<?php

if (!defined('ABSPATH')) {
    exit;
}

// Funciones Principales
function libre_custom_theme_setup() {
    // Agregamos el Soporte para Thumbnails
    add_theme_support('post-thumbnails');
    // Agregamos un tamaño de imagen y permitimos que la imagen se recorte si no cabe
    add_image_size('homepage-thumb', 745, 372, true);

    //Carga Traducciones
    load_theme_textdomain('Lidra', get_template_directory() . '/languages');

    // Agregamos el menu
    $locations = array(
        'main_nav' => __('Main Menu', 'Lidra'),
        'footer_nav' => __('Footer Menu', 'Lidra')
    );
    register_nav_menus($locations);
}
add_action('after_setup_theme', 'libre_custom_theme_setup');

// Funcion de reemplazo a leer más
function read_more($more) {
    $url_post = get_permalink();
    return "&nbsp;<a href='$url_post'><small>" . __('Read more...', 'Lidra') . "</small></a>";
}
add_filter('excerpt_more', 'read_more');

// Funcion de widget
function widgets_activation() {
    register_sidebar( array(
    'name' => __('Sidebar', 'Lidra'),
    'id' => 'sidebar',
    'before_widget' => '<div class="widget"><div class="titulo-seccion">',
    'after_widget' => '</div></div>',
    'before_title' => '<h3>',
    'after_title' => '</h3>'
    ));

}
add_action('widgets_init', 'widgets_activation');

/*
//Agrega iconos por defecto de WordPress
function load_dashicons_front_end() {
    wp_enqueue_style( 'dashicons' );
}
add_action( 'wp_enqueue_scripts', 'load_dashicons_front_end' );
*/

/*Ajustes y Limpieza para WordPress
------------------------------------------------------------------------------*/
//Elimina referencias a la version de WordPress
function quitar_version_wp() {
    return '';
}
add_filter('the_generator', 'quitar_version_wp');

function nowp_head_cleanup() {
    // Eliminamos lo que sobra de la cabecera
    remove_action('wp_head', 'rsd_link');
    remove_action('wp_head', 'wp_generator');
    remove_action('wp_head', 'feed_links', 2);
    remove_action('wp_head', 'index_rel_link');
    remove_action('wp_head', 'wlwmanifest_link');
    remove_action('wp_head', 'feed_links_extra', 3);
    remove_action('wp_head', 'start_post_rel_link', 10, 0);
    remove_action('wp_head', 'parent_post_rel_link', 10, 0);
    remove_action('wp_head', 'adjacent_posts_rel_link', 10, 0);
    remove_action('wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0);
    remove_action('wp_head', 'wp_shortlink_wp_head', 10, 0);
    remove_action('wp_head', 'feed_links', 2);
    remove_action('wp_head', 'feed_links_extra', 3);
    // Elimina emoji script
    remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
    remove_action( 'wp_print_styles', 'print_emoji_styles' );

    global $wp_widget_factory;
    remove_action('wp_head', array(
        $wp_widget_factory->widgets['WP_Widget_Recent_Comments'], 'recent_comments_style')
    );

    if (!class_exists('WPSEO_Frontend')) {
        remove_action('wp_head', 'rel_canonical');
        add_action('wp_head', 'nowp_rel_canonical');
    }
}
function nowp_rel_canonical() {
    global $wp_the_query;

    if (!is_singular()) {
        return;
    }

    if (!$id = $wp_the_query->get_queried_object_id()) {
        return;
    }

    $link = get_permalink($id);
    printf("<link rel=\"canonical\" href=\"$link\">\n");
}
add_action('init', 'nowp_head_cleanup');

// Limpia dns-prefetch en caso de NO usar fuentes del servicio Privativo Google
function remove_dns_prefetch($hints, $relation_type) {
    if ( 'dns-prefetch' === $relation_type ) {
        return array_diff( wp_dependencies_unique_hosts(), $hints );
    }

    return $hints;
}

add_filter( 'wp_resource_hints', 'remove_dns_prefetch', 10, 2 );

/* Limpiador de wp-embed
------------------------------------------------------------------------------*/
function disable_embeds_code_init() {
    // Remove the REST API endpoint.
    remove_action( 'rest_api_init', 'wp_oembed_register_route' );

    // Turn off oEmbed auto discovery.
    add_filter( 'embed_oembed_discover', '__return_false' );

    // Don't filter oEmbed results.
    remove_filter( 'oembed_dataparse', 'wp_filter_oembed_result', 10 );

    // Remove oEmbed discovery links.
    remove_action( 'wp_head', 'wp_oembed_add_discovery_links' );

    // Remove oEmbed-specific JavaScript from the front-end and back-end.
    remove_action( 'wp_head', 'wp_oembed_add_host_js' );
    add_filter( 'tiny_mce_plugins', 'disable_embeds_tiny_mce_plugin' );

    // Remove all embeds rewrite rules.
    add_filter( 'rewrite_rules_array', 'disable_embeds_rewrites' );

    // Remove filter of the oEmbed result before any HTTP requests are made.
    remove_filter( 'pre_oembed_result', 'wp_filter_pre_oembed_result', 10 );
}

add_action( 'init', 'disable_embeds_code_init', 9999 );

function disable_embeds_tiny_mce_plugin($plugins) {
    return array_diff($plugins, array('wpembed'));
}

function disable_embeds_rewrites($rules) {
    foreach($rules as $rule => $rewrite) {
        if(false !== strpos($rewrite, 'embed=true')) {
            unset($rules[$rule]);
        }
    }
    return $rules;
}

/* ViNotJS
------------------------------------------------------------------------------*/
include_once 'vinotjs/vinotjs.php';