html文档中的空线 - wordpress
我刚刚启动了新网站。一切正常,但是,我刚刚注意到HTML文档(页面的源代码)在“ <!doctype html>
”之前有15行。这引起了SEO的一些问题并生成自动站点地图。
我在网上搜索,最后找到了问题:我的孩子主题(店面)中的function.php。当我在子主题中删除或重命名function.php时,通常显示HTML DOC,没有空白空间。我尝试一个一个一个删除文件中编码的函数,但是问题仍然存在,直到我将所有函数删除为止。另外,我禁用了所有插件,什么也没有解决,只删除上述文件。有什么想法吗?非常感谢!
以下是functions.php的当前内容
add_filter( 'woocommerce_product_tabs', 'my_remove_all_product_tabs', 98 );
function my_remove_all_product_tabs( $tabs ) {
unset( $tabs['description'] ); // Remove the description tab
unset( $tabs['reviews'] ); // Remove the reviews tab
unset( $tabs['additional_information'] ); // Remove the additional information tab
return $tabs;
}
?>
<?php // Este snippet regula el tiempo que se muestra el cart widget del WCPT
function wcpt_cart_js() {
?>
<script type="text/javascript">
// your javscript code goes here
jQuery(function($){
$('body').on('wcpt_cart', function(){
setTimeout(function(){
$('.wcpt-cart-widget ').fadeOut();
}, 2000); // delay
})
})
</script>
<?php
}
add_action('wp_head', 'wcpt_cart_js');
?>
<?php
/* quitar "Menu" del hamburger en moviles */
add_filter( 'storefront_menu_toggle_text', 'storefront_menu_toggle_text' );
function storefront_menu_toggle_text( $text ) {
$text = __( '' );
return $text;
}
?>
<?php
/* quitar la barra menu inferior nativa storefront en moviles
add_action( 'init', 'jk_remove_storefront_handheld_footer_bar' );
function jk_remove_storefront_handheld_footer_bar() {
remove_action( 'storefront_footer', 'storefront_handheld_footer_bar', 999 );
}*/
?>
<?php
/**
* Custom Filter for Gallery Image Captions
*
* Note: Avoid altering captioning, selector, and item tag.
*/
function mlc_gallery_image_caption($attachment_id, $captiontag, $selector, $itemtag) {
$id = $attachment_id;
// Grab the meta from the GIC plugin.
$my_image_meta = galimgcaps_get_image_meta($id);
/**
* Here's where to customize the caption content.
*
* This example uses the meta title, caption, and description.
*
* You can display any value from the $my_image_meta array.
* You can add your HTML too.
*/
/*
return "<{$captiontag} class='wp-caption-text gallery-caption' id='{$selector}-{$id}'>" .
"Title: " . $my_image_meta['title'] . "<br>" .
"Caption: " . $my_image_meta['caption'] . "<br>".
"Description: ". $my_image_meta['description'] .
"</{$captiontag}></{$itemtag}>";
*/
return "<{$captiontag} class='wp-caption-text gallery-caption' id='{$selector}-{$id}'>" .
$my_image_meta['caption'] . "<br>".
"</{$captiontag}></{$itemtag}>";
}
add_filter('galimgcaps_gallery_image_caption', 'mlc_gallery_image_caption', 10, 4);
?>
<?php
/**
* Cambia el texto del boton "anadir al carrito"
*/
add_filter('woocommerce_product_single_add_to_cart_text','QL_customize_add_to_cart_button_woocommerce');
function QL_customize_add_to_cart_button_woocommerce(){
return __('Comprar', 'woocommerce');
}
?>
<?php
/**
* Override theme default specification for product # per row
*/
function loop_columns() {
return 4; // n products per row
}
add_filter('loop_shop_columns', 'loop_columns', 999);
?>
<?php
add_filter('woocommerce_product_add_to_cart_text', 'archive_custom_cart_button_text');
function archive_custom_cart_button_text()
{
return __('Comprar', 'woocommerce');
}
?>
<?php
add_filter( 'woocommerce_get_price_html', 'add_price_prefix', 99, 2 );
function add_price_prefix( $price, $product ){
$price = '' . $price;
return $price;
}
?>
<?php
if (wp_is_mobile()){
add_filter( 'the_title', 'shorten_woo_product_title_mobile', 10 , 2 );
/*mobile_storefront_page_header();*/
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 20 );
remove_action( 'woocommerce_before_single_product_summary', 'woocommerce_show_product_images', 20 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 6 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_show_product_images', 7 );
}
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20 );
?>
<?php
function shorten_woo_product_title_mobile( $title, $id ) {
if ( ! is_singular( array( 'product' ) ) && get_post_type( $id ) === 'product' && strlen( $title ) > 20 ) {
return substr( $title, 0, 42) . '..'; // change last number to the number of characters you want
} else {
return $title;
}
}
?>
<?php
function mobile_storefront_page_header() {
if ( is_single() ) {
return;
}
?>
<header class="entry-header">
<?php
the_title( '<h1 class="entry-title">', '</h1>' );
storefront_post_thumbnail( 'full' );
?>
</header><!-- .entry-header -->
<?php
}
?>
<?php
/**
* Redirecciona el productos de los resultados en tabla a la pagina seo optimizada del producto agrupado
*/
add_action('template_redirect','custom_shop_page_redirect');
function custom_shop_page_redirect(){
global $post;
if (class_exists('WooCommerce')){
if(is_product()){
$product = get_product( $post->ID );
if( $product->is_type( 'grouped' ) ){
$slug = get_queried_object()->post_name;
$nslug = str_replace("tienda/","",$slug);
for ($x = 0; $x <= 20; $x++) {
$nslug = rtrim($nslug,$x);}
$nslug = rtrim($nslug,"-");
wp_safe_redirect(home_url($nslug));
exit();
}
}
}
return;
}
?>
<?php
/**
* cambia el formato del precio de agrupados
*/
add_filter( 'woocommerce_grouped_price_html', 'grouped_price_range_delete', 'grouped_price_prefix', 10, 3, 2 );
function grouped_price_range_delete( $price, $product, $child_prices) {
$price = '';
return $price;
}
?>
<?php
/**
* actualiza automaticamente el carrito al cambiar la cantidad
*/
add_action( 'wp_footer', 'cart_update_qty_script' );
function cart_update_qty_script() {
if (is_cart()) :
?>
<script>
jQuery('div.woocommerce').on('change', '.qty', function(){
jQuery("[name='update_cart']").trigger("click");
});
</script>
<?php
endif;
}```
I just launched my new website. Everything is working ok, HOWEVER, I just noticed the HTML docs (source code of the page) has 15 blank lines before "<!doctype html>
". This is causing some issues for SEO and to generate automatic sitemaps.
I searched all over the web, and finally find the issue: the functions.php in my child theme (storefront). When I delete or rename the functions.php in the child theme, the HTML doc is shown normally without blank spaces. I tried deleting one by one the functions coded in the file, but the issue persists until I delete all functions together. Also, I disabled all plugins and nothing solves, only deleting the mentioned file. Any ideas? Thank you very much!
below is the current content of functions.php
add_filter( 'woocommerce_product_tabs', 'my_remove_all_product_tabs', 98 );
function my_remove_all_product_tabs( $tabs ) {
unset( $tabs['description'] ); // Remove the description tab
unset( $tabs['reviews'] ); // Remove the reviews tab
unset( $tabs['additional_information'] ); // Remove the additional information tab
return $tabs;
}
?>
<?php // Este snippet regula el tiempo que se muestra el cart widget del WCPT
function wcpt_cart_js() {
?>
<script type="text/javascript">
// your javscript code goes here
jQuery(function($){
$('body').on('wcpt_cart', function(){
setTimeout(function(){
$('.wcpt-cart-widget ').fadeOut();
}, 2000); // delay
})
})
</script>
<?php
}
add_action('wp_head', 'wcpt_cart_js');
?>
<?php
/* quitar "Menu" del hamburger en moviles */
add_filter( 'storefront_menu_toggle_text', 'storefront_menu_toggle_text' );
function storefront_menu_toggle_text( $text ) {
$text = __( '' );
return $text;
}
?>
<?php
/* quitar la barra menu inferior nativa storefront en moviles
add_action( 'init', 'jk_remove_storefront_handheld_footer_bar' );
function jk_remove_storefront_handheld_footer_bar() {
remove_action( 'storefront_footer', 'storefront_handheld_footer_bar', 999 );
}*/
?>
<?php
/**
* Custom Filter for Gallery Image Captions
*
* Note: Avoid altering captioning, selector, and item tag.
*/
function mlc_gallery_image_caption($attachment_id, $captiontag, $selector, $itemtag) {
$id = $attachment_id;
// Grab the meta from the GIC plugin.
$my_image_meta = galimgcaps_get_image_meta($id);
/**
* Here's where to customize the caption content.
*
* This example uses the meta title, caption, and description.
*
* You can display any value from the $my_image_meta array.
* You can add your HTML too.
*/
/*
return "<{$captiontag} class='wp-caption-text gallery-caption' id='{$selector}-{$id}'>" .
"Title: " . $my_image_meta['title'] . "<br>" .
"Caption: " . $my_image_meta['caption'] . "<br>".
"Description: ". $my_image_meta['description'] .
"</{$captiontag}></{$itemtag}>";
*/
return "<{$captiontag} class='wp-caption-text gallery-caption' id='{$selector}-{$id}'>" .
$my_image_meta['caption'] . "<br>".
"</{$captiontag}></{$itemtag}>";
}
add_filter('galimgcaps_gallery_image_caption', 'mlc_gallery_image_caption', 10, 4);
?>
<?php
/**
* Cambia el texto del boton "anadir al carrito"
*/
add_filter('woocommerce_product_single_add_to_cart_text','QL_customize_add_to_cart_button_woocommerce');
function QL_customize_add_to_cart_button_woocommerce(){
return __('Comprar', 'woocommerce');
}
?>
<?php
/**
* Override theme default specification for product # per row
*/
function loop_columns() {
return 4; // n products per row
}
add_filter('loop_shop_columns', 'loop_columns', 999);
?>
<?php
add_filter('woocommerce_product_add_to_cart_text', 'archive_custom_cart_button_text');
function archive_custom_cart_button_text()
{
return __('Comprar', 'woocommerce');
}
?>
<?php
add_filter( 'woocommerce_get_price_html', 'add_price_prefix', 99, 2 );
function add_price_prefix( $price, $product ){
$price = '' . $price;
return $price;
}
?>
<?php
if (wp_is_mobile()){
add_filter( 'the_title', 'shorten_woo_product_title_mobile', 10 , 2 );
/*mobile_storefront_page_header();*/
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 20 );
remove_action( 'woocommerce_before_single_product_summary', 'woocommerce_show_product_images', 20 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 6 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_show_product_images', 7 );
}
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20 );
?>
<?php
function shorten_woo_product_title_mobile( $title, $id ) {
if ( ! is_singular( array( 'product' ) ) && get_post_type( $id ) === 'product' && strlen( $title ) > 20 ) {
return substr( $title, 0, 42) . '..'; // change last number to the number of characters you want
} else {
return $title;
}
}
?>
<?php
function mobile_storefront_page_header() {
if ( is_single() ) {
return;
}
?>
<header class="entry-header">
<?php
the_title( '<h1 class="entry-title">', '</h1>' );
storefront_post_thumbnail( 'full' );
?>
</header><!-- .entry-header -->
<?php
}
?>
<?php
/**
* Redirecciona el productos de los resultados en tabla a la pagina seo optimizada del producto agrupado
*/
add_action('template_redirect','custom_shop_page_redirect');
function custom_shop_page_redirect(){
global $post;
if (class_exists('WooCommerce')){
if(is_product()){
$product = get_product( $post->ID );
if( $product->is_type( 'grouped' ) ){
$slug = get_queried_object()->post_name;
$nslug = str_replace("tienda/","",$slug);
for ($x = 0; $x <= 20; $x++) {
$nslug = rtrim($nslug,$x);}
$nslug = rtrim($nslug,"-");
wp_safe_redirect(home_url($nslug));
exit();
}
}
}
return;
}
?>
<?php
/**
* cambia el formato del precio de agrupados
*/
add_filter( 'woocommerce_grouped_price_html', 'grouped_price_range_delete', 'grouped_price_prefix', 10, 3, 2 );
function grouped_price_range_delete( $price, $product, $child_prices) {
$price = '';
return $price;
}
?>
<?php
/**
* actualiza automaticamente el carrito al cambiar la cantidad
*/
add_action( 'wp_footer', 'cart_update_qty_script' );
function cart_update_qty_script() {
if (is_cart()) :
?>
<script>
jQuery('div.woocommerce').on('change', '.qty', function(){
jQuery("[name='update_cart']").trigger("click");
});
</script>
<?php
endif;
}```
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我很抱歉。现在解决了,我发现问题是每个PHP打开/关闭之间的空白线。对不起,无用的帖子。
问候!
I'm very sorry. Is now solved, i found the problem was the blank lines between each php open/close. Sorry for the useless post.
Regards!