文件操作 - functions.php
返回文件管理
返回主菜单
删除本文件
文件: /storage/v12552/i2kplay/public_html/wp-content/themes/flatsome-child/functions.php
编辑文件内容
<?php /** * Enables the HTTP Strict Transport Security (HSTS) header in WordPress. */ // require get_template_directory() . '/inc/init.php'; // flatsome()->init(); add_action( 'send_headers', 'enable_strict_transport_security_hsts_header_wordpress' ); function enable_strict_transport_security_hsts_header_wordpress() { header( 'Strict-Transport-Security: max-age=31536000; includeSubDomains; preload' ); } /** * Remove Blocked by X-Robots-Tag: noindex HTTP header in WordPress. */ add_action( 'send_headers', 'set_X_Robots_Tag', 99 ); function set_X_Robots_Tag() { if(is_wc_endpoint_url('lost-password')){ header( 'X-Robots-Tag: index, follow'); } } // function force_jquery_in_admin() { // wp_deregister_script('jquery'); // wp_register_script('jquery', includes_url('/js/jquery/jquery.min.js'), false, '3.6.0', true); // wp_enqueue_script('jquery'); // } // add_action('admin_enqueue_scripts', 'force_jquery_in_admin', 1); function your_theme_enqueue_styles() { $parent_style = 'parent-style'; wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css'); wp_enqueue_style( 'child-style', get_stylesheet_directory_uri() . '/style.css', array($parent_style)); wp_enqueue_style('flickity-css', 'https://cdnjs.cloudflare.com/ajax/libs/flickity/2.3.0/flickity.min.css'); wp_enqueue_script('flickity-js', 'https://cdnjs.cloudflare.com/ajax/libs/flickity/2.3.0/flickity.pkgd.min.js', array('jquery'), 'null', true); wp_enqueue_script( 'custom-slider', get_stylesheet_directory_uri() . '/assets/js/slider.js', array('flickity-js'), '1.1.10', // Use null to prevent query strings for versioning true ); // wp_enqueue_script( // 'top-nav-slider', // get_stylesheet_directory_uri('/assets/js/slider.js', __FILE__), // // plugins_url('/assets/js/agent-scripts.js', __FILE__), // array('flickity-js'), // filemtime(get_stylesheet_directory_uri(__FILE__) . '/assets/js/slider.js'), // true // ); } add_action('wp_enqueue_scripts', 'your_theme_enqueue_styles'); //Change the Billing Details checkout label to Your Details add_filter( 'gettext', 'wc_billing_field_strings', 20, 3 ); function wc_billing_field_strings( $translated_text, $text, $domain ) { switch ( $translated_text ) { case 'Billing details' : $translated_text = __( 'Customer Details', 'woocommerce' ); break; } return $translated_text; } /* Add meta viewport */ add_action( 'wp_head', 'add_viewport_meta_tag' , '1' ); function add_viewport_meta_tag() { echo '<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" scalable="yes" maximum-scale="{2 or higher}">'; } add_filter('get_comment_author_link', 'binary_carpenter_remove_nofollow', 10, 1); add_filter('comment_text', 'binary_carpenter_remove_nofollow', 10, 1); function binary_carpenter_remove_nofollow($content) { $content = preg_replace("/(<a[^>]*[^\s])(\s*nofollow\s*)/i", "$1", $content); $content = preg_replace("/(<a[^>]*[^\s])(\s*rel=[\"\']\s*[\"\'])/i", "$1", $content); return $content; } /* custom script in header */ add_action('wp_head', 'add_custom_script', 10); function add_custom_script(){ ?> <script type="text/javascript"> jQuery(document).ready(function(){ setTimeout(function(){ if(jQuery('.zsiq_flt_rel').length > 0){ jQuery('.zsiq_flt_rel').attr('tabindex', '0'); jQuery('.zsiq_flt_rel').attr('role', 'button'); } }, 2000); if(jQuery('.specs-button').length > 0){ jQuery('.specs-button').attr('aria-label', 'opens in a new tab'); } if(jQuery('.bg.bg-fill').length > 0){ jQuery('.bg.bg-fill').attr('aria-label', 'Background Image'); jQuery('.bg.bg-fill').attr('role', 'img'); } if(jQuery('.icon-phone').length > 0){ jQuery('.icon-phone').attr('role', 'none'); } if(jQuery('.icon-angle-down').length > 0){ jQuery('.icon-angle-down').attr('role', 'none'); } }); </script> <?php } /* Change meta robots for cart, myaccount and checkout */ add_filter( 'rank_math/frontend/robots', function( $robots ) { if(is_page('my-account') || is_page('cart') || is_page('checkout')){ $robots['index'] = 'index'; } return $robots; }); add_shortcode('custom_primary_menu', 'add_custom_primary_menu'); function add_custom_primary_menu(){ ob_start(); wp_nav_menu(array( 'menu' => 'primary-menu', 'container' => 'div', 'container_class' => '', 'container_id' => '', 'container_aria_label' => '', 'menu_class' => 'menu', 'items_wrap' => '<ul id="%1$s" class="%2$s" role="navigation">%3$s</ul>', 'theme_location' => '' )); return ob_get_clean(); } add_filter( 'nav_menu_link_attributes', function ( $atts, $item, $args ) { if ( 2025 === $item->ID ) { $atts['aria-haspopup'] = 'true'; $atts['aria-expanded'] = 'true'; } return $atts; }, 10, 3 ); /* Change meta content length */ add_filter( 'rank_math/frontend/description', function( $description ) { $str = $description; $substr = substr($str, 0, 145) . '...'; $description = $substr; return $description; }); /* Change meta title length */ add_filter( 'rank_math/frontend/title', function( $title ) { if(is_singular('post')){ if(strpos($title, 'i2k Inflatable') !== false){ $new_title = str_replace(' - i2k Inflatable', '', $title); $title = $new_title; } } return $title; }); /* 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']) && $_SERVER['QUERY_STRING'] != ''){ $New_canonical = $canonical; return $New_canonical; } else { return $canonical; } }); /* Change comment cancel reply link */ add_filter( "cancel_comment_reply_link", "modify_cancel_comment_reply_link", 10, 3 ); function modify_cancel_comment_reply_link($formatted_link, $link, $text) { $formatted_link = '<a id="cancel-comment-reply-link" href="'.$link.'" style="display:none;" data-kmt="1">'.$text.'</a>'; return $formatted_link; } /* Change comment reply link */ add_filter( "comment_reply_link", "modify_comment_reply_link", 10, 4 ); function modify_comment_reply_link($link, $args, $comment, $post) { $comment_id = get_comment_ID($comment); $comment_link = get_permalink($post->ID).'?replytocom='.$comment_id.'#respond'; $link = '<a class="comment-reply-link" href="'.$comment_link.'" data-commentid="'.$comment_id.'" data-postid="'.$post->ID.'" data-belowelement="comment-'.$comment_id.'" data-respondelement="respond" data-replyto="Reply to '.$post->post_title.'" aria-label="Reply to '.$post->post_title.'" data-kmt="1">Reply</a>'; return $link; } // Change Add to Cart button text on the shop and product pages add_filter('woocommerce_product_add_to_cart_text', 'custom_add_to_cart_text'); // For archive pages add_filter('woocommerce_product_single_add_to_cart_text', 'custom_add_to_cart_text'); // For single product pages function custom_add_to_cart_text() { return __('Add To Cart', 'woocommerce'); // Replace 'Buy Now' with your desired text }
修改文件时间
将文件时间修改为当前时间的前一年
删除文件