使用子主题覆盖函数,无法使其在我的functions.php中工作

时间:2017-07-21 09:26:42

标签: php wordpress function

我已经在主题文件夹中编辑了一个functions.php,以确保它不会覆盖我做过子主题的文件。我只是无法在我的functions.php中获取函数覆盖。我把调试模式放在遇到以下错误。我也尝试给函数另一个名字,它不起作用。

希望有人可以帮助我!

  

错误地调用了wp_enqueue_script

     

致命错误:无法重新声明accesspress_pro_bx_slider_cb()(之前>在> /home/ersiteweb/domains/ersite.website/public_html/zaliginantwerpen/wp-> content / themes / accesspress-pro-child / functions中声明。 php:34)在> /home/ersiteweb/domains/ersite.website/public_html/zaliginantwerpen/wp->内容/ themes / accesspress-pro / inc / accesspress-functions.php第651行

function accesspress_pro_bx_slider_cb() {

                global $accesspress_pro_options;
                $accesspress_pro_settings = get_option( 'accesspress_pro_options', $accesspress_pro_options );
                $slider_images = $accesspress_pro_settings['slider'];
                $slider_show_pager = $accesspress_pro_settings['slider_show_pager'] == 'yes1' ? 'true' : 'false';
                $slider_show_controls = $accesspress_pro_settings['slider_show_controls'] == 'yes2' ? 'true' : 'false';
                $slider_auto = $accesspress_pro_settings['slider_auto'] == 'yes3' ? 'true' : 'false';

                $count = count($slider_images);
                $total = 0;
                ?>
                    <script type="text/javascript">
                    jQuery(function(){
                    jQuery('.bx-slider').bxSlider({
                    adaptiveHeight : true,
                    pager:<?php echo $slider_show_pager; ?>,
                    controls:<?php echo $slider_show_controls; ?>,
                    mode:'fade',
                    auto :<?php echo $slider_auto; ?>,
                    pause: '<?php echo $accesspress_pro_settings['slider_speed']; ?>',
                    speed: 1000,
                    });
                    });
                    </script>

                    <div class="bx-slider">
                    <?php
                        if(!empty($slider_images )){
                        foreach ($slider_images as $slider_image) {
                        $total++;
                    ?>

                    <div class="slides">
        <img src="<?php echo $slider_image['banner']; ?>">

                    <?php if($accesspress_pro_settings['slider_caption']=='yes4'): ?>
                    <div class="slider-caption">
                    <div class="ak-container">
                    <?php if($slider_image['caption_header']): ?>
                    <div class="title">
                        <div class="hidenow1"><h1><?php the_field('title1_1');?></h1></div>
                        <div class="hidenow1"><h1><?php the_field('title1_1');?></h1></div>
                        <div class="hidenow2"><h1><?php the_field('title1_2');?></h1></div>
                        <div class="hidenow3"><h1><?php the_field('title1_3');?></h1></div>
                        <div class="hidenow4"><h1><?php the_field('title1_4');?></h1></div>
                        <div class="hidenow5"><h1><?php the_field('title1_5');?></h1></div>
                        <div class="hidenow6"><h1><?php the_field('title1_6');?></h1></div>
                        <div class="hidenow7"><h1><?php the_field('title1_7');?></h1></div>
                        <div class="hidenow8"><h1><?php the_field('title1_8');?></h1></div>
                        <div class="hidenow9"><h1><?php the_field('title1_9');?></h1></div>
                        <h1 class="caption-title"><?php echo $slider_image['caption_header']; ?></h1>
                    </div> <!--title -->
                    <?php endif; ?>

                 <?php if($slider_image['caption_desc']): ?>
                     <div class="subtitle">
                    <div class="hidenow1"><p><?php the_field('subtitle1_1');?></p></div>
                    <div class="hidenow2"><p><?php the_field('subtitle1_2');?></p></div>
                    <div class="hidenow3"><p><?php the_field('subtitle1_3');?></p></div>
                    <div class="hidenow4"><p><?php the_field('subtitle1_4');?></p></div>
                    <div class="hidenow5"><p><?php the_field('subtitle1_5');?></p></div>
                    <div class="hidenow6"><p><?php the_field('subtitle1_6');?></p></div>
                    <div class="hidenow7"><p><?php the_field('subtitle1_7');?></p></div>
                    <div class="hidenow8"><p><?php the_field('subtitle1_8');?></p></div>
                    <div class="hidenow9"><p><?php the_field('subtitle1_9');?></p></div>
                 <h1 class="caption-description"><?php echo $slider_image['caption_desc']; ?></h1>
             </div><!--subtitle-->
                <?php endif; ?>

                <?php if(!empty($slider_image['slider_read_more'])) :?>
                <a class="more-link" href="<?php echo $slider_image['slider_read_more_link']; ?>"><?php echo $slider_image['slider_read_more']; ?></a>
                <?php endif; ?>

            </div> <!--akcontainer-->
            </div> <!--slidecaption -->
             <?php  endif; ?>

                </div> <!--slides -->
                                <?php
                                }
                            } ?>
                </div> <!--bxslider -->
                <?php
   } //function


 add_action( 
 'wp_enqueue_scripts','accesspress_pro_sequence_slider','accesspress_pro_se
  quence_slider_cb');

1 个答案:

答案 0 :(得分:0)

在php中你不能覆盖类。 要解决您的错误,您必须在文件accesspress-function.php或文件functions.php中更改您的函数名称,如果您想更改它。

在accesspress-function.php中修改:

if (!function_exists('accesspress_pro_bx_slider_cb')) {
  function accesspress_pro_bx_slider_cb() {
    .........
  }
}

我也邀请您阅读This guide to functions wordpress child theme