348 lines
13 KiB
PHP
348 lines
13 KiB
PHP
<?php
|
|
/**
|
|
* Author: Alejandro Castro
|
|
* URL: alcastromol.com
|
|
* Custom functions, support, custom post types and more.
|
|
*/
|
|
|
|
/*------------------------------------*\
|
|
External Modules/Files
|
|
\*------------------------------------*/
|
|
|
|
// Load any external files you have here
|
|
require_once get_template_directory() . '/parts/page-transition/page-transition.php';
|
|
require_once get_template_directory() . '/parts/smooth-scroll/smooth-scroll.php';
|
|
require_once get_template_directory() . '/parts/scroll-progress/scroll-progress.php';
|
|
require_once get_template_directory() . '/parts/animated-background/animated-background.php';
|
|
//require_once get_template_directory() . '/parts/fluid-cursor/fluid-cursor.php';
|
|
require_once get_template_directory() . '/parts/spotlight-cursor/spotlight-cursor.php';
|
|
require_once get_template_directory() . '/parts/solutions-title-animation/solutions-title-animation.php';
|
|
require_once get_template_directory() . '/parts/practice-card-tilt/practice-card-tilt.php';
|
|
require_once get_template_directory() . '/parts/platform-card-tilt/platform-card-tilt.php';
|
|
|
|
/*------------------------------------*\
|
|
Theme Support
|
|
\*------------------------------------*/
|
|
|
|
if ( ! isset( $content_width ) ) {
|
|
$content_width = 900;
|
|
}
|
|
|
|
if ( function_exists( 'add_theme_support' ) ) {
|
|
|
|
// Add Thumbnail Theme Support.
|
|
add_theme_support( 'post-thumbnails' );
|
|
add_image_size( 'large', 700, '', true ); // Large Thumbnail.
|
|
add_image_size( 'medium', 250, '', true ); // Medium Thumbnail.
|
|
add_image_size( 'small', 120, '', true ); // Small Thumbnail.
|
|
add_image_size( 'custom-size', 700, 200, true ); // Custom Thumbnail Size call using the_post_thumbnail('custom-size');
|
|
|
|
// Enables post and comment RSS feed links to head.
|
|
add_theme_support( 'automatic-feed-links' );
|
|
add_theme_support( 'title-tag' );
|
|
|
|
// Enable HTML5 support.
|
|
add_theme_support( 'html5', array( 'comment-list', 'comment-form', 'search-form', 'gallery', 'caption' ) );
|
|
add_theme_support( 'rank-math-breadcrumbs' );
|
|
|
|
// Localisation Support.
|
|
load_theme_textdomain( 'html5blank', get_template_directory() . '/languages' );
|
|
}
|
|
|
|
/**
|
|
* Theme navigation locations.
|
|
*/
|
|
function xmartica_register_navigation() {
|
|
register_nav_menus(
|
|
array(
|
|
'primary' => esc_html__( 'Header ETS', 'html5blank' ),
|
|
)
|
|
);
|
|
}
|
|
add_action( 'after_setup_theme', 'xmartica_register_navigation' );
|
|
|
|
/**
|
|
* Allow the trusted SVG assets used by the theme to live in the media library.
|
|
*/
|
|
function xmartica_allowed_upload_mimes( $mimes ) {
|
|
$mimes['svg'] = 'image/svg+xml';
|
|
|
|
return $mimes;
|
|
}
|
|
add_filter( 'upload_mimes', 'xmartica_allowed_upload_mimes' );
|
|
|
|
function xmartica_svg_filetype_and_ext( $data, $file, $filename, $mimes ) {
|
|
if ( 'svg' !== strtolower( pathinfo( $filename, PATHINFO_EXTENSION ) ) ) {
|
|
return $data;
|
|
}
|
|
|
|
$data['ext'] = 'svg';
|
|
$data['type'] = 'image/svg+xml';
|
|
$data['proper_filename'] = $filename;
|
|
|
|
return $data;
|
|
}
|
|
add_filter( 'wp_check_filetype_and_ext', 'xmartica_svg_filetype_and_ext', 10, 4 );
|
|
|
|
/**
|
|
* A single-menu fallback for new installs where the Header ETS menu has not
|
|
* been assigned yet.
|
|
*/
|
|
function xmartica_primary_menu_fallback( $args ) {
|
|
$class = isset( $args['menu_class'] ) ? $args['menu_class'] : 'xmartica-menu';
|
|
|
|
echo '<ul class="' . esc_attr( $class ) . '">';
|
|
echo '<li><a href="' . esc_url( home_url( '/#soluciones' ) ) . '">' . esc_html__( 'Soluciones', 'html5blank' ) . '</a></li>';
|
|
echo '<li><a href="' . esc_url( home_url( '/#preguntas-frecuentes' ) ) . '">' . esc_html__( 'Preguntas Frecuentes', 'html5blank' ) . '</a></li>';
|
|
echo '</ul>';
|
|
}
|
|
|
|
/**
|
|
* Per-page footer claim. Empty values inherit the default ETS message.
|
|
*/
|
|
function xmartica_add_footer_claim_meta_box() {
|
|
add_meta_box(
|
|
'xmartica-footer-claim',
|
|
esc_html__( 'Texto principal del footer', 'html5blank' ),
|
|
'xmartica_render_footer_claim_meta_box',
|
|
'page',
|
|
'normal',
|
|
'default'
|
|
);
|
|
}
|
|
add_action( 'add_meta_boxes', 'xmartica_add_footer_claim_meta_box' );
|
|
|
|
function xmartica_render_footer_claim_meta_box( $post ) {
|
|
$value = get_post_meta( $post->ID, 'footer_claim', true );
|
|
wp_nonce_field( 'xmartica_save_footer_claim', 'xmartica_footer_claim_nonce' );
|
|
?>
|
|
<p>
|
|
<label for="xmartica-footer-claim-field">
|
|
<?php esc_html_e( 'Déjalo vacío para usar “Transformación con ejecución real.”', 'html5blank' ); ?>
|
|
</label>
|
|
</p>
|
|
<input
|
|
type="text"
|
|
id="xmartica-footer-claim-field"
|
|
name="footer_claim"
|
|
value="<?php echo esc_attr( $value ); ?>"
|
|
class="widefat"
|
|
maxlength="140"
|
|
>
|
|
<?php
|
|
}
|
|
|
|
function xmartica_save_footer_claim( $post_id ) {
|
|
if ( ! isset( $_POST['xmartica_footer_claim_nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['xmartica_footer_claim_nonce'] ) ), 'xmartica_save_footer_claim' ) ) {
|
|
return;
|
|
}
|
|
|
|
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
|
|
return;
|
|
}
|
|
|
|
if ( ! current_user_can( 'edit_page', $post_id ) ) {
|
|
return;
|
|
}
|
|
|
|
$value = isset( $_POST['footer_claim'] ) ? sanitize_text_field( wp_unslash( $_POST['footer_claim'] ) ) : '';
|
|
|
|
if ( '' === $value ) {
|
|
delete_post_meta( $post_id, 'footer_claim' );
|
|
return;
|
|
}
|
|
|
|
update_post_meta( $post_id, 'footer_claim', $value );
|
|
}
|
|
add_action( 'save_post_page', 'xmartica_save_footer_claim' );
|
|
|
|
/*------------------------------------*\
|
|
Functions
|
|
\*------------------------------------*/
|
|
|
|
// Load HTML5 Blank scripts (header.php)
|
|
function html5blank_header_scripts() {
|
|
|
|
// Custom scripts
|
|
wp_register_script(
|
|
'scripts',
|
|
get_template_directory_uri() . '/js/scripts.js',
|
|
array(
|
|
// 'conditionizr',
|
|
// 'modernizr',
|
|
// 'jquery'
|
|
),
|
|
filemtime( get_template_directory() . '/js/scripts.js' ) );
|
|
|
|
// Enqueue Scripts
|
|
wp_enqueue_script( 'scripts' );
|
|
|
|
}
|
|
|
|
// Load HTML5 Blank styles
|
|
function stylestheme() {
|
|
// Custom CSS
|
|
wp_register_style( 'html5blankcssmin', get_template_directory_uri() . '/style.css', array(), filemtime( get_template_directory() . '/style.css' ) );
|
|
// Register CSS
|
|
wp_enqueue_style( 'html5blankcssmin' );
|
|
|
|
$geist_light = wp_get_attachment_url( 9 );
|
|
$geist_regular = wp_get_attachment_url( 10 );
|
|
$geist_semibold = wp_get_attachment_url( 11 );
|
|
$jetbrains_mono_medium = wp_get_attachment_url( 15 );
|
|
|
|
if ( $geist_light && $geist_regular && $geist_semibold ) {
|
|
$font_css = sprintf(
|
|
'@font-face{font-family:"Geist";src:url("%1$s") format("woff2");font-style:normal;font-weight:300;font-display:swap}@font-face{font-family:"Geist";src:url("%2$s") format("woff2");font-style:normal;font-weight:400;font-display:swap}@font-face{font-family:"Geist";src:url("%3$s") format("woff2");font-style:normal;font-weight:600;font-display:swap}%4$s',
|
|
esc_url_raw( $geist_light ),
|
|
esc_url_raw( $geist_regular ),
|
|
esc_url_raw( $geist_semibold ),
|
|
$jetbrains_mono_medium ? sprintf( '@font-face{font-family:"JetBrains Mono";src:url("%s") format("woff2");font-style:normal;font-weight:500;font-display:swap}', esc_url_raw( $jetbrains_mono_medium ) ) : ''
|
|
);
|
|
wp_add_inline_style( 'html5blankcssmin', $font_css );
|
|
}
|
|
}
|
|
|
|
// Add page slug to body class, love this - Credit: Starkers Wordpress Theme
|
|
function add_slug_to_body_class( $classes ) {
|
|
global $post;
|
|
if ( is_front_page() ) {
|
|
$classes[] = 'front-page';
|
|
}
|
|
if ( is_home() ) {
|
|
$key = array_search( 'blog', $classes, true );
|
|
if ( $key > -1 ) {
|
|
unset( $classes[$key] );
|
|
}
|
|
} elseif ( is_page() ) {
|
|
$classes[] = sanitize_html_class( $post->post_name );
|
|
} elseif ( is_singular() ) {
|
|
$classes[] = sanitize_html_class( $post->post_name );
|
|
}
|
|
|
|
return $classes;
|
|
}
|
|
|
|
// Remove wp_head() injected Recent Comment styles
|
|
function my_remove_recent_comments_style() {
|
|
global $wp_widget_factory;
|
|
|
|
if ( isset( $wp_widget_factory->widgets['WP_Widget_Recent_Comments'] ) ) {
|
|
remove_action( 'wp_head', array(
|
|
$wp_widget_factory->widgets['WP_Widget_Recent_Comments'],
|
|
'recent_comments_style'
|
|
) );
|
|
}
|
|
}
|
|
|
|
// Pagination for paged posts, Page 1, Page 2, Page 3, with Next and Previous Links, No plugin
|
|
function html5wp_pagination() {
|
|
global $wp_query;
|
|
$big = 999999999;
|
|
echo paginate_links( array(
|
|
'base' => str_replace( $big, '%#%', get_pagenum_link( $big ) ),
|
|
'format' => '?paged=%#%',
|
|
'current' => max( 1, get_query_var( 'paged' ) ),
|
|
'total' => $wp_query->max_num_pages,
|
|
) );
|
|
}
|
|
|
|
// Custom View Article link to Post
|
|
function html5_blank_view_article( $more ) {
|
|
global $post;
|
|
|
|
if ( isset( $post->post_type ) && 'page' === $post->post_type ) {
|
|
return '';
|
|
}
|
|
|
|
$permalink = isset( $post->ID ) ? get_permalink( $post->ID ) : '';
|
|
|
|
return '... <a class="view-article" href="' . esc_url( $permalink ) . '">' . esc_html__( 'View Article', 'html5blank' ) . '</a>';
|
|
}
|
|
|
|
// Remove Admin bar
|
|
function remove_admin_bar() {
|
|
return false;
|
|
}
|
|
|
|
// Threaded Comments
|
|
function enable_threaded_comments() {
|
|
if ( ! is_admin() ) {
|
|
if ( is_singular() AND comments_open() AND ( get_option( 'thread_comments' ) == 1 ) ) {
|
|
wp_enqueue_script( 'comment-reply' );
|
|
}
|
|
}
|
|
}
|
|
|
|
// Custom Comments Callback
|
|
function html5blankcomments( $comment, $args, $depth ) {
|
|
$GLOBALS['comment'] = $comment;
|
|
extract( $args, EXTR_SKIP );
|
|
|
|
if ( 'div' == $args['style'] ) {
|
|
$tag = 'div';
|
|
$add_below = 'comment';
|
|
} else {
|
|
$tag = 'li';
|
|
$add_below = 'div-comment';
|
|
}
|
|
?>
|
|
<!-- heads up: starting < for the html tag (li or div) in the next line: -->
|
|
<<?php echo esc_html( $tag ) ?> <?php comment_class( empty( $args['has_children'] ) ? '' : 'parent' ) ?> id="comment-<?php comment_ID(); ?>">
|
|
<?php if ( 'div' != $args['style'] ) : ?>
|
|
<div id="div-comment-<?php comment_ID(); ?>" class="comment-body">
|
|
<?php endif; ?>
|
|
<div class="comment-author vcard">
|
|
<?php if ( $args['avatar_size'] != 0 ) echo get_avatar( $comment, $args['avatar_size'] ); ?>
|
|
<?php printf( esc_html( '<cite class="fn">%s</cite> <span class="says">says:</span>' ), get_comment_author_link() ) ?>
|
|
</div>
|
|
<?php if ( $comment->comment_approved == '0' ) : ?>
|
|
<em class="comment-awaiting-moderation"><?php esc_html_e( 'Your comment is awaiting moderation.' ) ?></em>
|
|
<br />
|
|
<?php endif; ?>
|
|
|
|
<div class="comment-meta commentmetadata"><a href="<?php echo htmlspecialchars( get_comment_link( $comment->comment_ID ) ) ?>">
|
|
<?php
|
|
printf( esc_html( '%1$s at %2$s' ), get_comment_date(), get_comment_time() ) ?></a><?php edit_comment_link( esc_html_e( '(Edit)' ), ' ', '' );
|
|
?>
|
|
</div>
|
|
|
|
<?php comment_text() ?>
|
|
|
|
<div class="reply">
|
|
<?php comment_reply_link( array_merge( $args, array('add_below' => $add_below, 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ) ?>
|
|
</div>
|
|
<?php if ( 'div' != $args['style'] ) : ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
<?php }
|
|
|
|
/*------------------------------------*\
|
|
Actions + Filters + ShortCodes
|
|
\*------------------------------------*/
|
|
|
|
// Add Actions
|
|
add_action( 'wp_enqueue_scripts', 'html5blank_header_scripts' ); // Add Custom Scripts to wp_head
|
|
add_action( 'get_header', 'enable_threaded_comments' ); // Enable Threaded Comments
|
|
add_action( 'wp_enqueue_scripts', 'stylestheme' ); // Add Theme Stylesheet
|
|
|
|
add_action( 'widgets_init', 'my_remove_recent_comments_style' ); // Remove inline Recent Comment Styles from wp_head()
|
|
add_action( 'init', 'html5wp_pagination' ); // Add our HTML5 Pagination
|
|
|
|
// Remove Actions
|
|
remove_action( 'wp_head', 'feed_links_extra', 3 ); // Display the links to the extra feeds such as category feeds
|
|
remove_action( 'wp_head', 'feed_links', 2 ); // Display the links to the general feeds: Post and Comment Feed
|
|
remove_action( 'wp_head', 'rsd_link' ); // Display the link to the Really Simple Discovery service endpoint, EditURI link
|
|
remove_action( 'wp_head', 'wlwmanifest_link' ); // Display the link to the Windows Live Writer manifest file.
|
|
remove_action( 'wp_head', 'wp_generator' ); // Display the XHTML generator that is generated on the wp_head hook, WP version
|
|
remove_action( 'wp_head', 'rel_canonical' );
|
|
remove_action( 'wp_head', 'wp_shortlink_wp_head', 10, 0 );
|
|
|
|
// Add Filters
|
|
add_filter( 'body_class', 'add_slug_to_body_class' ); // Add slug to body class (Starkers build)
|
|
|
|
add_filter( 'the_excerpt', 'shortcode_unautop' ); // Remove auto <p> tags in Excerpt (Manual Excerpts only)
|
|
add_filter( 'the_excerpt', 'do_shortcode' ); // Allows Shortcodes to be executed in Excerpt (Manual Excerpts only)
|
|
add_filter( 'excerpt_more', 'html5_blank_view_article' ); // Add 'View Article' button instead of [...] for Excerpts
|
|
add_filter( 'show_admin_bar', 'remove_admin_bar' ); // Remove Admin bar
|