Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在所有页面上显示自定义函数_Php_Css_Wordpress_Woocommerce_Hook Woocommerce - Fatal编程技术网

Php 在所有页面上显示自定义函数

Php 在所有页面上显示自定义函数,php,css,wordpress,woocommerce,hook-woocommerce,Php,Css,Wordpress,Woocommerce,Hook Woocommerce,WordPress |店面|追求商业。 我尝试在桌面视图上显示页眉,在移动设备上显示页脚,以响应特定的页面id 1。但即使使用特定的页面id,这两个类也会显示在页面id 1页眉、页脚。我尝试使用层次结构的级联规则来显示id和类。此处id abc显示在页面id 1桌面视图上,而abcd显示在页面id 1移动设备上。 我的child function.php代码是 add_action( 'storefront_header', 'header_content1', 30 ); fu

WordPress |店面|追求商业。 我尝试在桌面视图上显示页眉,在移动设备上显示页脚,以响应特定的页面id 1。但即使使用特定的页面id,这两个类也会显示在页面id 1页眉、页脚。我尝试使用层次结构的级联规则来显示id和类。此处id abc显示在页面id 1桌面视图上,而abcd显示在页面id 1移动设备上。 我的child function.php代码是

      add_action( 'storefront_header', 'header_content1', 30 );
  function header_content1() { ?>
    <div id/class="abc" > my text with css</div><?php
  }
  add_action( 'storefront_after_footer', 'header_content2', 10 );
  function header_content2() { ?>
    <div id/class="abcd" > my text with css</div><?php

    }

}更好的方法是只在需要的页面上加载函数,而不是将HTML隐藏在除一个页面外的所有页面中

您可以在运行函数之前检查页面ID,如下所示:

if (is_page('1') {
    add_action( 'storefront_header', 'header_content1', 30 );
    function header_content1() { ?>
        <div id/class="abc" > my text with css</div><?php
    }
}
if(是第页('1')){
添加_操作('storefront_header','header_content1',30);
函数头_content1(){?>

实际上,在header_content1()函数中放入
if(is_page('1'){}
语句会更简洁。
if (is_page('1') {
    add_action( 'storefront_header', 'header_content1', 30 );
    function header_content1() { ?>
        <div id/class="abc" > my text with css</div><?php
    }
}