functions.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <?php
  2. if (!defined('ABSPATH')){
  3. exit;
  4. }
  5. // Funciones Principales
  6. function libre_custom_theme_setup(){
  7. // Agregamos el Soporte para Thumbnails
  8. add_theme_support('post-thumbnails');
  9. // Agregamos un tamaño de imagen y permitimos que la imagen se recorte si no cabe
  10. add_image_size('homepage-thumb', 745, 372, true);
  11. //Carga Traducciones
  12. load_theme_textdomain('Lidra', get_template_directory() . '/languages');
  13. // Agregamos el menu
  14. $locations = array(
  15. 'main_nav' => __('Main Menu', 'Lidra'),
  16. 'footer_nav' => __('Footer Menu', 'Lidra')
  17. );
  18. register_nav_menus($locations);
  19. }
  20. add_action('after_setup_theme', 'libre_custom_theme_setup');
  21. // Funcion de reemplazo a leer más
  22. function read_more( $more ){
  23. $url_post = get_permalink();
  24. return "&nbsp;<a href='$url_post'><small>" . __('Read more...', 'Lidra') . "</small></a>";
  25. }
  26. add_filter('excerpt_more', 'read_more');
  27. // Funcion de widget
  28. function widgets_activation(){
  29. register_sidebar( array(
  30. 'name' => __('Sidebar', 'Lidra'),
  31. 'id' => 'sidebar',
  32. 'before_widget' => '<div class="widget"><div class="titulo-seccion">',
  33. 'after_widget' => '</div></div>',
  34. 'before_title' => '<h3>',
  35. 'after_title' => '</h3>'
  36. ));
  37. }
  38. add_action('widgets_init', 'widgets_activation');
  39. //Agrega iconos por defecto de WordPress
  40. function load_dashicons_front_end() {
  41. wp_enqueue_style( 'dashicons' );
  42. }
  43. add_action( 'wp_enqueue_scripts', 'load_dashicons_front_end' );
  44. /*Ajustes y Limpieza para WordPress
  45. ------------------------------------------------------------------------------*/
  46. //Elimina referencias a la version de WordPress
  47. function quitar_version_wp() {
  48. return '';
  49. }
  50. add_filter('the_generator', 'quitar_version_wp');
  51. function nowp_head_cleanup() {
  52. // Eliminamos lo que sobra de la cabecera
  53. remove_action('wp_head', 'rsd_link');
  54. remove_action('wp_head', 'wp_generator');
  55. remove_action('wp_head', 'feed_links', 2);
  56. remove_action('wp_head', 'index_rel_link');
  57. remove_action('wp_head', 'wlwmanifest_link');
  58. remove_action('wp_head', 'feed_links_extra', 3);
  59. remove_action('wp_head', 'start_post_rel_link', 10, 0);
  60. remove_action('wp_head', 'parent_post_rel_link', 10, 0);
  61. remove_action('wp_head', 'adjacent_posts_rel_link', 10, 0);
  62. remove_action('wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0);
  63. remove_action('wp_head', 'wp_shortlink_wp_head', 10, 0);
  64. remove_action('wp_head', 'feed_links', 2);
  65. remove_action('wp_head', 'feed_links_extra', 3);
  66. // Elimina emoji script
  67. remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
  68. remove_action( 'wp_print_styles', 'print_emoji_styles' );
  69. global $wp_widget_factory;
  70. remove_action('wp_head', array(
  71. $wp_widget_factory->widgets['WP_Widget_Recent_Comments'], 'recent_comments_style')
  72. );
  73. if (!class_exists('WPSEO_Frontend')) {
  74. remove_action('wp_head', 'rel_canonical');
  75. add_action('wp_head', 'nowp_rel_canonical');
  76. }
  77. }
  78. function nowp_rel_canonical() {
  79. global $wp_the_query;
  80. if (!is_singular()) {
  81. return;
  82. }
  83. if (!$id = $wp_the_query->get_queried_object_id()) {
  84. return;
  85. }
  86. $link = get_permalink($id);
  87. printf("<link rel=\"canonical\" href=\"$link\">\n");
  88. }
  89. add_action('init', 'nowp_head_cleanup');
  90. // Limpia dns-prefetch en caso de NO usar fuentes del servicio Privativo Google
  91. function remove_dns_prefetch( $hints, $relation_type ) {
  92. if ( 'dns-prefetch' === $relation_type ) {
  93. return array_diff( wp_dependencies_unique_hosts(), $hints );
  94. }
  95. return $hints;
  96. }
  97. add_filter( 'wp_resource_hints', 'remove_dns_prefetch', 10, 2 );
  98. /* Limpiador de wp-embed
  99. ------------------------------------------------------------------------------*/
  100. function disable_embeds_code_init() {
  101. // Remove the REST API endpoint.
  102. remove_action( 'rest_api_init', 'wp_oembed_register_route' );
  103. // Turn off oEmbed auto discovery.
  104. add_filter( 'embed_oembed_discover', '__return_false' );
  105. // Don't filter oEmbed results.
  106. remove_filter( 'oembed_dataparse', 'wp_filter_oembed_result', 10 );
  107. // Remove oEmbed discovery links.
  108. remove_action( 'wp_head', 'wp_oembed_add_discovery_links' );
  109. // Remove oEmbed-specific JavaScript from the front-end and back-end.
  110. remove_action( 'wp_head', 'wp_oembed_add_host_js' );
  111. add_filter( 'tiny_mce_plugins', 'disable_embeds_tiny_mce_plugin' );
  112. // Remove all embeds rewrite rules.
  113. add_filter( 'rewrite_rules_array', 'disable_embeds_rewrites' );
  114. // Remove filter of the oEmbed result before any HTTP requests are made.
  115. remove_filter( 'pre_oembed_result', 'wp_filter_pre_oembed_result', 10 );
  116. }
  117. add_action( 'init', 'disable_embeds_code_init', 9999 );
  118. function disable_embeds_tiny_mce_plugin($plugins) {
  119. return array_diff($plugins, array('wpembed'));
  120. }
  121. function disable_embeds_rewrites($rules) {
  122. foreach($rules as $rule => $rewrite) {
  123. if(false !== strpos($rewrite, 'embed=true')) {
  124. unset($rules[$rule]);
  125. }
  126. }
  127. return $rules;
  128. }
  129. /* ViNotJS
  130. ------------------------------------------------------------------------------*/
  131. include_once 'vinotjs/vinotjs.php';