文件操作 - functions.php
返回文件管理
返回主菜单
删除本文件
文件: /storage/v12552/avantibackupsite/public_html/wp-content/themes/hello-theme-child/functions.php
编辑文件内容
<?php /** * Theme functions and definitions * * @package HelloElementorChild */ /** * Enables the HTTP Strict Transport Security (HSTS) header in WordPress. */ function tg_enable_strict_transport_security_hsts_header_wordpress() { header( 'Strict-Transport-Security: max-age=31536000' ); } add_action( 'send_headers', 'tg_enable_strict_transport_security_hsts_header_wordpress' ); /** * Load child theme css and optional scripts * * @return void */ function hello_elementor_child_enqueue_scripts() { wp_enqueue_style( 'hello-elementor-child-style', get_stylesheet_directory_uri() . '/style.css', [ 'hello-elementor-theme-style', ], rand(1, 11111) ); } add_action( 'wp_enqueue_scripts', 'hello_elementor_child_enqueue_scripts', 20 ); /*Custom Post type start*/ add_action('init', 'cp_post_type_avanti_treatments'); function cp_post_type_avanti_treatments() { $supports = array( 'title', // post title 'editor', // post content 'author', // post author 'thumbnail', // featured images 'excerpt', // post excerpt 'revisions' // post revisions ); $labels = array( 'name' => _x('Avanti treatments', 'plural'), 'singular_name' => _x('Avanti treatments', 'singular'), 'menu_name' => _x('Avanti treatments', 'admin menu'), 'name_admin_bar' => _x('Avanti treatments', 'admin bar'), 'add_new' => _x('Add New', 'add new'), 'add_new_item' => __('Add New treatment'), 'new_item' => __('New treatment'), 'edit_item' => __('Edit treatment'), 'view_item' => __('View treatments'), 'all_items' => __('All treatments'), 'search_items' => __('Search treatments'), 'not_found' => __('No treatments found.'), ); $args = array( 'supports' => $supports, 'labels' => $labels, 'public' => true, 'query_var' => true, 'has_archive' => true, 'hierarchical' => false, ); register_post_type('avanti_treatments', $args); } /* Add meta box for CPT */ add_action( 'add_meta_boxes', 'custom_text_meta_box' ); function custom_text_meta_box() { add_meta_box( 'treatment-heading', __( 'Treatment Box Top Heading', 'sitepoint' ), 'custom_meta_box_callback', 'avanti_treatments', 'normal', 'high' ); } function custom_meta_box_callback(){ global $post; // Add a nonce field so we can check for it later. wp_nonce_field( 'custom_heading_nonce', 'custom_heading_nonce' ); $value = get_post_meta( $post->ID, '_treatment_heading', true ); echo '<textarea style="width:100%" id="treatment_heading" name="treatment_heading">' . esc_attr( $value ) . '</textarea>'; } add_action('save_post', 'save_custom_meta_box_data'); function save_custom_meta_box_data( $post_id ) { // Check if our nonce is set. if ( ! isset( $_POST['custom_heading_nonce'] ) ) { return; } // Check the user's permissions. if ( isset( $_POST['post_type'] ) && $_POST['post_type'] == 'avanti_treatments') { // Sanitize user input. $my_data = sanitize_text_field( $_POST['treatment_heading'] ); // Update the meta field in the database. update_post_meta( $post_id, '_treatment_heading', $my_data ); } } /* End custom Meta Box */ function custom_menu_page_removing() { $users_emails = array('terri@avantibody.com', 'bernardo@revel8ionmedia.com', 'brice@revel8ionmedia.com', 'jessica@revel8ionmedia.com'); if ( in_array(get_currentuserinfo()->user_email, $users_emails)){ remove_menu_page( 'wpel-settings-page' ); } } add_action( 'admin_menu', 'custom_menu_page_removing' ); /* Shortcode to display Treatments on home page */ add_shortcode('avanti_treatment', 'display_treatments_data'); function display_treatments_data(){ ob_start(); $args = array( 'post_type' => 'avanti_treatments', 'posts_per_page' => 20, 'post_status' => 'publish', 'orderby' => 'date', 'order' => 'ASC' ); $treatment = new WP_Query($args); if($treatment->have_posts()){ ?> <script type="text/javascript"> jQuery(document).ready(function(){ jQuery('.treatment-widget-column').slick({ infinite: true, speed: 300, prevArrow: '<button class="slide-arrow prev-arrow"></button>', nextArrow: '<button class="slide-arrow next-arrow"></button>', slidesToShow: 4, slidesToScroll: 1, responsive: [ { breakpoint: 1024, settings: { slidesToShow: 3, slidesToScroll: 1, infinite: true } }, { breakpoint: 600, settings: { slidesToShow: 2, slidesToScroll: 1 } }, { breakpoint: 480, settings: { slidesToShow: 1, slidesToScroll: 1 } } ] }); }); </script> <section class="home-treatment-sec"> <div class="treatment-widget-wrap"> <div class="treatment-widget-column"> <?php while($treatment->have_posts()) : $treatment->the_post(); $post_id = get_the_ID(); $headings = get_post_meta($post_id, '_treatment_heading', true); ?> <div class="widget-item"> <div class="item-top"> <div class="box-header"> <h3><?php echo $headings;?></h3> </div> <div class="item-thumbnail"> <?php if(has_post_thumbnail()) : ?> <?php the_post_thumbnail('large');?> <?php endif;?> </div> </div> <div class="item-bottom"> <div class="content-section"> <div class="content-wrapper"> <h4><?php echo get_the_title();?></h4> <p> <?php $excerpt = substr(get_the_excerpt(), 0, 130); echo $excerpt.' ...'; ?> </p> </div> <div class="carousel_btn"> <a class="ultimate_carousel_btn" href="<?php echo home_url();?>">LEARN MORE</a> </div> </div> </div> </div> <?php endwhile;?> <?php wp_reset_query(); ?> </div> </div> </section> <?php } return ob_get_clean(); } add_action('wp_head', 'add_custom_scripts', 10); function add_custom_scripts(){ ?> <script type="text/javascript"> jQuery(document).ready(function(){ if(jQuery('button.needsclick').length > 0){ jQuery('button.needsclick').attr('aria-label', 'Button'); } if(jQuery('input.needsclick').length > 0){ jQuery('input.needsclick').attr('aria-label', 'combobox'); } if(jQuery('div.needsclick').length > 0){ jQuery('div.needsclick').attr('aria-label', 'listbox'); } if(jQuery('.sub-arrow').length > 0){ alert('yes'); jQuery('.sub-arrow').attr('role', 'none'); } if(jQuery('i.fa-angle-down').length > 0){ jQuery('i.fa-angle-down').attr('role', 'none'); } if(jQuery('span#elementor-device-mode').length > 0){ jQuery('span#elementor-device-mode').attr('role', 'none'); } if(jQuery('svg.e-font-icon-svg-symbols').length > 0){ jQuery('svg.e-font-icon-svg-symbols').attr('role', 'none'); } }); </script> <?php if(is_page('avanti-body-weight-loss-centers')){ ?> <script type="text/javascript"> jQuery(document).ready(function(){ if(jQuery('.dialog-lightbox-widget video').length > 0){ jQuery('.dialog-lightbox-widget video').attr('preload', 'auto'); } }); </script> <?php } } /* Programtically add Async to styles and scripts */ add_filter('style_loader_tag', 'add_async_attribute', 10, 2); function add_async_attribute($html, $handle) { $styles_to_async = array('wp-block-library', 'elementor-frontend', 'elementor-global', 'elementor-icons-shared-0', 'ekit-widget-styles', 'elementor-icons-ekiticons'); if(is_page('avanti-body-lake-zurich-weight-loss-center') || is_page('avanti-body-weight-loss-centers')){ if (!in_array($handle, $styles_to_async)) { return $html; } else { return str_replace('href', ' async="async" href', $html); } } return $html; } /* Redirect links programatically */ add_action( 'template_redirect', 'redirect_custom_urls'); function redirect_custom_urls(){ global $wp; $current_url = add_query_arg(array(), $wp->request); if(!is_admin()){ if($current_url){ if(strpos($current_url, '[link]') !== false){ $new_url_arr = explode('[link]', $current_url); $new_url = home_url('/').$new_url_arr[0]; wp_redirect($new_url, 301); exit(); } } } } /* Set canonical url for Alternate page with proper canonical tag */ // add_filter( 'rank_math/frontend/canonical', function( $canonical ) { // global $wp; // if(isset($_SERVER['QUERY_STRING'])){ // if(isset($_SERVER['REDIRECT_URL'])){ // $canonical = home_url() . $_SERVER['REDIRECT_URL']; // } else { // $canonical = home_url('/'); // } // } // return $canonical; // }); add_filter( 'rank_math/frontend/canonical', function( $canonical ) { if(isset($_SERVER['QUERY_STRING']) && $_SERVER['QUERY_STRING'] != ''){ $canonical = home_url() . $_SERVER['REDIRECT_URL']; } return $canonical; }); /* Shortcode to display Treatments on home page */ add_shortcode('blog_heading', 'display_blog_heading'); function display_blog_heading(){ ob_start(); if(is_page('blog') || (!is_front_page() && is_home())){ ?> <h1 class="elementor-heading-title elementor-size-default" style="color: #000000;font-size: 60px; text-align: center;">Avanti Body Blogs</h1> <?php } return ob_get_clean(); } /* Remove extra meta description hook */ add_action('init', 'remove_custom_hooks', 10); function remove_custom_hooks(){ remove_action('wp_head', 'hello_elementor_add_description_meta_tag'); } /* Change Author URL */ add_filter( 'request', 'wpse_request' ); function wpse_request( $query_vars ){ if ( array_key_exists( 'author_name', $query_vars ) ) { global $wpdb; $author_id = $wpdb->get_var( $wpdb->prepare( "SELECT user_id FROM {$wpdb->usermeta} WHERE meta_key='nickname' AND meta_value = %s", $query_vars['author_name'] ) ); if ( $author_id ) { $query_vars['author'] = $author_id; unset( $query_vars['author_name'] ); } } return $query_vars; } /* replacing the standard author part (indicated by $author_nicename) with the nickname */ add_filter( 'author_link', 'wpse_author_link', 10, 3 ); function wpse_author_link( $link, $author_id, $author_nicename ){ $author_nickname = get_user_meta( $author_id, 'nickname', true ); if ( $author_nickname ) { $new_slug = str_replace(' ', '-', strtolower($author_nickname)); $new_slug = str_replace('_', '-', $new_slug); $link = str_replace( $author_nicename, $new_slug, $link ); } return $link; } /* Changing the data that forms the author URL */ add_action( 'user_profile_update_errors', 'wpse_set_user_nicename_to_nickname', 10, 3 ); function wpse_set_user_nicename_to_nickname( &$errors, $update, &$user ){ if ( ! empty( $user->nickname ) ) { $user_nickname = str_replace(' ', '-', strtolower($user->nickname)); $user_nickname = str_replace('_', '-', $user_nickname); $user_displayname = str_replace(' ', '-', strtolower($user->display_name)); $user_displayname = str_replace('_', '-', $user_displayname); $user->user_nicename = sanitize_title( $user_nickname, $user_displayname ); } }
修改文件时间
将文件时间修改为当前时间的前一年
删除文件