Child-Theme functions.php not taken into account

Dear AThemes team,

I want to be able to write a slider title on two lines, and to achieve this, I planned to write a pipe character in the title, that will be then replaced by a line break using a personnalized function in my child theme.

I based my solution on this topic:

Here is the details of what I did. Can you please tell me if i forgot something, and why my code doesn’t seem to be executed ?:

– I created a child theme;
– I copy-paste the function sydney_slider_template() in the child’s ‘functions.php’ file as described above;
– I added some code after the initialisation of the variables $slider_title_x and $slider_subtitle_x:
$slider_title_1 = str_replace(’ | ', ‘<br />’, $slider_title_1);

I activated my child theme, and in the theme customiser, I wrote a title for the first silde, with a pipe in the middle.
What is expected, is that my overriden function replace the pipe with a line break, but instead, I have my title with the pipe.

Did I forgot to do something ? (I hope i gave enough details!)

Thank you in advance,
Tom

Dear Tom,

Does the slide title you inserted look like this:


Lorem ipsum | dolor sit amet

(see the left/right single space)?

Regards,
Kharis

Yes, exactly Kharis :slight_smile:

Here is the full code of my child’s theme functions.php file:
(please look for the comments [TRO] in the code to see where my modifications are :-))

<?php
/**
 * Sydney child functions
 *
 */

/**
 * Enqueues the parent stylesheet. Do not remove this function.
 *
 */
add_action( 'wp_enqueue_scripts', 'sydney_child_enqueue' );
function sydney_child_enqueue() {
    
    wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );

}

/* ADD YOUR CUSTOM FUNCTIONS BELOW */
/*
    [TRO]
    Copied from original theme, 'sydney/inc/slider.php'
    CHeck for pipes to replace by line break.
*/
function sydney_slider_template() {
    if ( (get_theme_mod('front_header_type','slider') == 'slider' && is_front_page()) || (get_theme_mod('site_header_type') == 'slider' && !is_front_page()) ) {

    //Get the slider options
    $speed      = get_theme_mod('slider_speed', '4000');
    $text_slide = get_theme_mod('textslider_slide', 0);

    //Slider text
    if ( !function_exists('pll_register_string') ) {
        $slider_title_1     = get_theme_mod('slider_title_1', 'Welcome to Sydney');
        $slider_title_2     = get_theme_mod('slider_title_2', 'Ready to begin your journey?');
        $slider_title_3     = get_theme_mod('slider_title_3');
        $slider_title_4     = get_theme_mod('slider_title_4');
        $slider_title_5     = get_theme_mod('slider_title_5');
        $slider_subtitle_1  = get_theme_mod('slider_subtitle_1','Feel free to look around');
        $slider_subtitle_2  = get_theme_mod('slider_subtitle_2', 'Click the button below');
        $slider_subtitle_3  = get_theme_mod('slider_subtitle_3');
        $slider_subtitle_4  = get_theme_mod('slider_subtitle_4');
        $slider_subtitle_5  = get_theme_mod('slider_subtitle_5');
    } else {
        $slider_title_1     = pll__(get_theme_mod('slider_title_1', 'Welcome to Sydney'));
        $slider_title_2     = pll__(get_theme_mod('slider_title_2', 'Ready to begin your journey?'));
        $slider_title_3     = pll__(get_theme_mod('slider_title_3'));
        $slider_title_4     = pll__(get_theme_mod('slider_title_4'));
        $slider_title_5     = pll__(get_theme_mod('slider_title_5'));
        $slider_subtitle_1  = pll__(get_theme_mod('slider_subtitle_1','Feel free to look around'));
        $slider_subtitle_2  = pll__(get_theme_mod('slider_subtitle_2', 'Click the button below'));
        $slider_subtitle_3  = pll__(get_theme_mod('slider_subtitle_3'));
        $slider_subtitle_4  = pll__(get_theme_mod('slider_subtitle_4'));
        $slider_subtitle_5  = pll__(get_theme_mod('slider_subtitle_5'));  
    }
        
        
/* [TRO] - Replace pipes by <br/> */
    $slider_title_1 = str_replace(' | ', '<br />', $slider_title_1);
    $slider_title_2 = str_replace(' | ', '<br />', $slider_title_2);
    $slider_title_3 = str_replace(' | ', '<br />', $slider_title_3);
    $slider_title_4 = str_replace(' | ', '<br />', $slider_title_4);
    $slider_title_5 = str_replace(' | ', '<br />', $slider_title_5);
    $slider_subtitle_1 = str_replace(' | ', '<br />', $slider_subtitle_1);
    $slider_subtitle_2 = str_replace(' | ', '<br />', $slider_subtitle_2);
    $slider_subtitle_3 = str_replace(' | ', '<br />', $slider_subtitle_3);
    $slider_subtitle_4 = str_replace(' | ', '<br />', $slider_subtitle_4);
    $slider_subtitle_5 = str_replace(' | ', '<br />', $slider_subtitle_5);
/* [/TRO] */

    ?>

    <div id="slideshow" class="header-slider" data-speed="<?php echo esc_attr($speed); ?>">
        <div class="slides-container">
            <?php 
                if ( get_theme_mod('slider_image_1', get_template_directory_uri() . '/images/1.png') ) {
                    echo '<div class="slide-item" style="background-image:url(' . esc_url(get_theme_mod('slider_image_1', get_template_directory_uri() . '/images/1.jpg')) . ');">';
                    ?>
                        <div class="slide-inner">
                            <div class="contain animated fadeInRightBig text-slider">
                                <h2 class="maintitle"><?php echo esc_html($slider_title_1); ?></h2>
                                <p class="subtitle"><?php echo esc_html($slider_subtitle_1); ?></p>
                            </div>
                            <?php sydney_slider_button(); ?>
                        </div>
                    <?php
                    echo '</div>';
                
                }
                if ( get_theme_mod('slider_image_2', get_template_directory_uri() . '/images/2.jpg') ) {
                    echo '<div class="slide-item" style="background-image:url(' . esc_url(get_theme_mod('slider_image_2', get_template_directory_uri() . '/images/2.jpg')) . ');">';
                    ?>
                        <div class="slide-inner">
                            <div class="contain animated fadeInRightBig text-slider">
                                <h2 class="maintitle"><?php echo esc_html($slider_title_2); ?></h2>
                                <p class="subtitle"><?php echo esc_html($slider_subtitle_2); ?></p>
                            </div>
                            <?php sydney_slider_button(); ?> 
                        </div>                   
                    <?php
                    echo '</div>';
                }           
                if ( get_theme_mod('slider_image_3') ) {
                    echo '<div class="slide-item" style="background-image:url(' . esc_url(get_theme_mod('slider_image_3')) . ');">';
                    ?>
                        <div class="slide-inner">                    
                            <div class="contain animated fadeInRightBig text-slider">
                                <h2 class="maintitle"><?php echo esc_html($slider_title_3); ?></h2>
                                <p class="subtitle"><?php echo esc_html($slider_subtitle_3); ?></p>
                            </div>
                            <?php sydney_slider_button(); ?>
                        </div>                         
                    <?php                    
                    echo '</div>';
                }
                if ( get_theme_mod('slider_image_4') ) {
                    echo '<div class="slide-item" style="background-image:url(' . esc_url(get_theme_mod('slider_image_4')) . ');">';
                    ?>
                        <div class="slide-inner">                                        
                            <div class="contain animated fadeInRightBig text-slider">
                                <h2 class="maintitle"><?php echo esc_html($slider_title_4); ?></h2>
                                <p class="subtitle"><?php echo esc_html($slider_subtitle_4); ?></p>
                            </div>
                            <?php sydney_slider_button(); ?>
                        </div>                        
                    <?php                    
                    echo '</div>';
                }
                if ( get_theme_mod('slider_image_5') ) {
                    echo '<div class="slide-item" style="background-image:url(' . esc_url(get_theme_mod('slider_image_5')) . ');">';
                    ?>
                        <div class="slide-inner">                                                            
                            <div class="contain animated fadeInRightBig text-slider">
                                <h2 class="maintitle"><?php echo esc_html($slider_title_5); ?></h2>
                                <p class="subtitle"><?php echo esc_html($slider_subtitle_5); ?></p>
                            </div>
                            <?php sydney_slider_button(); ?> 
                        </div>                                              
                    <?php                    
                    echo '</div>';
                }               
            ?>  
        </div>        
    </div>

    <?php if ( $text_slide ) : ?>
        <?php echo sydney_stop_text(); ?>
    <?php endif; ?>

    <?php
    }
}

The code seems fine.

Is your site being cached by a plugin like W3 Total Cache? If so, please empty all cache and try again.

Regards,
Kharis

No, sorry, i don’t have such plugin installed.

Here is the style.css from my child-theme, maybe i made a mistake in the referencing there:

/*
    Theme Name: Sydney Child
    Theme URI: https://athemes.com/theme/sydney
    Author: aThemes
    Author URI: https://athemes.com
    Template: sydney
    Version: 1.31
    License: GNU General Public License v2 or later
    License URI: http://www.gnu.org/licenses/gpl-2.0.html
    Text Domain: sydney
*/

Hello there,

Please share the working login credentials to your site admin area, so I can take a closer it. Please email it to kharisblank@gmail.com and enclose the link to this thread.

Regards,
Kharis

Hope you received well my email :slight_smile:

Hi, here is a little update,
I fiddled a bit with my child theme trying to dig out the solution from Internet, but I still can’t get it to work…
Here are my files with their exact content:

style.css

/*
Theme Name: Sydney Child
Theme URI: https://athemes.com/theme/sydney
Author: aThemes
Author URI: https://athemes.com
Template: sydney
Version: 1.0
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Text Domain: sydney
*/

functions.php

<?php
/* This method doesn't seem to work
add_action( 'wp_enqueue_scripts', 'sydney_child_enqueue' );
function sydney_child_enqueue() {   
    wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
}
*/

/* This method doesn't seem to work either
add_action( 'wp_enqueue_scripts', 'sydney_child_enqueue' );
function sydney_child_enqueue() {
    wp_enqueue_style( 'sydney', get_template_directory_uri() . '/style.css' );
}
*/

/* Nor this one... */
function sydney_child_enqueue_styles() {
	$parent_style = 'sydney';

	wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' );
	wp_enqueue_style( 'sydney-child',
		get_stylesheet_directory_uri() . '/style.css',
		array( $parent_style )
	);
}
add_action( 'wp_enqueue_scripts', 'sydney_child_enqueue_styles' );

/* ADD YOUR CUSTOM FUNCTIONS BELOW */
/*
    [TRO]
    Copied from original theme, 'sydney/inc/slider.php'
    CHeck for pipes to replace by line break.
*/
function sydney_slider_template() {
    if ( (get_theme_mod('front_header_type','slider') == 'slider' && is_front_page()) || (get_theme_mod('site_header_type') == 'slider' && !is_front_page()) ) {

    //Get the slider options
    $speed      = get_theme_mod('slider_speed', '4000');
    $text_slide = get_theme_mod('textslider_slide', 0);

    //Slider text
    if ( !function_exists('pll_register_string') ) {
        $slider_title_1     = get_theme_mod('slider_title_1', 'Welcome to Sydney');
        $slider_title_2     = get_theme_mod('slider_title_2', 'Ready to begin your journey?');
        $slider_title_3     = get_theme_mod('slider_title_3');
        $slider_title_4     = get_theme_mod('slider_title_4');
        $slider_title_5     = get_theme_mod('slider_title_5');
        $slider_subtitle_1  = get_theme_mod('slider_subtitle_1','Feel free to look around');
        $slider_subtitle_2  = get_theme_mod('slider_subtitle_2', 'Click the button below');
        $slider_subtitle_3  = get_theme_mod('slider_subtitle_3');
        $slider_subtitle_4  = get_theme_mod('slider_subtitle_4');
        $slider_subtitle_5  = get_theme_mod('slider_subtitle_5');
    } else {
        $slider_title_1     = pll__(get_theme_mod('slider_title_1', 'Welcome to Sydney'));
        $slider_title_2     = pll__(get_theme_mod('slider_title_2', 'Ready to begin your journey?'));
        $slider_title_3     = pll__(get_theme_mod('slider_title_3'));
        $slider_title_4     = pll__(get_theme_mod('slider_title_4'));
        $slider_title_5     = pll__(get_theme_mod('slider_title_5'));
        $slider_subtitle_1  = pll__(get_theme_mod('slider_subtitle_1','Feel free to look around'));
        $slider_subtitle_2  = pll__(get_theme_mod('slider_subtitle_2', 'Click the button below'));
        $slider_subtitle_3  = pll__(get_theme_mod('slider_subtitle_3'));
        $slider_subtitle_4  = pll__(get_theme_mod('slider_subtitle_4'));
        $slider_subtitle_5  = pll__(get_theme_mod('slider_subtitle_5'));  
    }
        
        
/* [TRO] - Replace pipes by <br/> */
    $slider_title_1 = str_replace(' | ', '<br />', $slider_title_1);
    $slider_title_2 = str_replace(' | ', '<br />', $slider_title_2);
    $slider_title_3 = str_replace(' | ', '<br />', $slider_title_3);
    $slider_title_4 = str_replace(' | ', '<br />', $slider_title_4);
    $slider_title_5 = str_replace(' | ', '<br />', $slider_title_5);
    $slider_subtitle_1 = str_replace(' | ', '<br />', $slider_subtitle_1);
    $slider_subtitle_2 = str_replace(' | ', '<br />', $slider_subtitle_2);
    $slider_subtitle_3 = str_replace(' | ', '<br />', $slider_subtitle_3);
    $slider_subtitle_4 = str_replace(' | ', '<br />', $slider_subtitle_4);
    $slider_subtitle_5 = str_replace(' | ', '<br />', $slider_subtitle_5);
/* [/TRO] */

    ?>

    <div id="slideshow" class="header-slider" data-speed="<?php echo esc_attr($speed); ?>">
        <div class="slides-container">
            <?php 
                if ( get_theme_mod('slider_image_1', get_template_directory_uri() . '/images/1.png') ) {
                    echo '<div class="slide-item" style="background-image:url(' . esc_url(get_theme_mod('slider_image_1', get_template_directory_uri() . '/images/1.jpg')) . ');">';
                    ?>
                        <div class="slide-inner">
                            <div class="contain animated fadeInRightBig text-slider">
                                <h2 class="maintitle"><?php echo esc_html($slider_title_1); ?></h2>
                                <p class="subtitle"><?php echo esc_html($slider_subtitle_1); ?></p>
                            </div>
                            <?php sydney_slider_button(); ?>
                        </div>
                    <?php
                    echo '</div>';
                
                }
                if ( get_theme_mod('slider_image_2', get_template_directory_uri() . '/images/2.jpg') ) {
                    echo '<div class="slide-item" style="background-image:url(' . esc_url(get_theme_mod('slider_image_2', get_template_directory_uri() . '/images/2.jpg')) . ');">';
                    ?>
                        <div class="slide-inner">
                            <div class="contain animated fadeInRightBig text-slider">
                                <h2 class="maintitle"><?php echo esc_html($slider_title_2); ?></h2>
                                <p class="subtitle"><?php echo esc_html($slider_subtitle_2); ?></p>
                            </div>
                            <?php sydney_slider_button(); ?> 
                        </div>                   
                    <?php
                    echo '</div>';
                }           
                if ( get_theme_mod('slider_image_3') ) {
                    echo '<div class="slide-item" style="background-image:url(' . esc_url(get_theme_mod('slider_image_3')) . ');">';
                    ?>
                        <div class="slide-inner">                    
                            <div class="contain animated fadeInRightBig text-slider">
                                <h2 class="maintitle"><?php echo esc_html($slider_title_3); ?></h2>
                                <p class="subtitle"><?php echo esc_html($slider_subtitle_3); ?></p>
                            </div>
                            <?php sydney_slider_button(); ?>
                        </div>                         
                    <?php                    
                    echo '</div>';
                }
                if ( get_theme_mod('slider_image_4') ) {
                    echo '<div class="slide-item" style="background-image:url(' . esc_url(get_theme_mod('slider_image_4')) . ');">';
                    ?>
                        <div class="slide-inner">                                        
                            <div class="contain animated fadeInRightBig text-slider">
                                <h2 class="maintitle"><?php echo esc_html($slider_title_4); ?></h2>
                                <p class="subtitle"><?php echo esc_html($slider_subtitle_4); ?></p>
                            </div>
                            <?php sydney_slider_button(); ?>
                        </div>                        
                    <?php                    
                    echo '</div>';
                }
                if ( get_theme_mod('slider_image_5') ) {
                    echo '<div class="slide-item" style="background-image:url(' . esc_url(get_theme_mod('slider_image_5')) . ');">';
                    ?>
                        <div class="slide-inner">                                                            
                            <div class="contain animated fadeInRightBig text-slider">
                                <h2 class="maintitle"><?php echo esc_html($slider_title_5); ?></h2>
                                <p class="subtitle"><?php echo esc_html($slider_subtitle_5); ?></p>
                            </div>
                            <?php sydney_slider_button(); ?> 
                        </div>                                              
                    <?php                    
                    echo '</div>';
                }               
            ?>  
        </div>        
    </div>

    <?php if ( $text_slide ) : ?>
        <?php echo sydney_stop_text(); ?>
    <?php endif; ?>

    <?php
    }
}

Hello there,

So sorry for the long delay.

I got your email. I just replied it.

Regards,
Kharis

I’m having problems with my sites slider images…
they’re not appearing anymore after installing the Sydney child theme!
please help…
Here’s a link to the web
http://www.thewebville.gq/

Hello there,

Thank you for posting in. I replied your query on WP.org support forum: https://wordpress.org/support/topic/slider-image-not-showing-up-2/

Regards,
Kharis