0

I have a multilingual site setup: www.jeroenbrugman.com

The main dutch version uses Fluxus. On the artwork page I output a link using this from Functions.php

function prefix_term_name($terms, $post_id, $taxonomy ) {
  foreach ($terms as &$term) {
    $term->name = 'Terug naar '.$term->name;
  }
}
  return $terms;

And on the page itself I show it using this:

 <h3 class="widget-title">
                                <?php
  add_filter( 'get_the_terms','prefix_term_name',10,3);
  the_terms($post->ID, 'fluxus-project-type'); 
  remove_filter( 'get_the_terms','prefix_term_name',10,3); ?>
                                <a href="../"><?php the_terms($post->ID, 'fluxus-project-type'); ?></a></h3>

But, on my English page. I need to output the 'Terug naar' from the main theme function.php as: 'Back To'. but when I copy the code from main functions.php to my child theme's functions.php and change Terug naar to Back to the whole english site goes blank.

What am I doing wrong?

Kind regards

2 Answers 2

1

You need to make the function pluggable, that means, to support child themes, the functions in parent theme should use:

if ( !function_exists( 'function_name' )) {
    function function_name() {
        //Stuffs
    }
}  

You should have seen a PHP Error message if you have debugging enabled.

EDIT: The below code snippet if to answer your other question in comment.

function modify_read_more_link() {
    global $post;

    return '<a class="more-link" href="' . get_permalink( $post->ID ) . '">Your Read More Link Text</a>';

}
add_filter( 'the_content_more_link', 'modify_read_more_link' );
10
  • So this if ( !function_exists( 'function_name' )) { function function_name() { function prefix_term_name($terms, $post_id, $taxonomy ) { foreach ($terms as &$term) { $term->name = 'Terug naar '.$term->name; } } return $terms; } } Should be in my parent theme's functions.php. And I will be able to use the same code without your code in my child theme's functions.php? Nov 27, 2015 at 21:05
  • I also tried this for the modify_read_more_link function. Making it pluggable in the function.php of my main theme. This didn't work tho. if ( !function_exists( 'modify_read_more_link' )) { add_filter( 'the_content_more_link', 'modify_read_more_link' ); function modify_read_more_link() { return '<a class="more-link" href="' . get_permalink() . '">Read more</a>'; } } This was the code used with your plugging Nov 27, 2015 at 22:03
  • Could you help me one more time? Nov 28, 2015 at 9:08
  • @ginobrugman what happens when you add the code above? Is there any other function with name modify_read_more_link exists in parent theme?
    – Abhik
    Nov 28, 2015 at 10:07
  • I made it pluggable. Even put it above the prefix_term_name function mentioned earlier. None of this works. Also there are no other functions using modify_read_more_link Nov 28, 2015 at 12:29
0

Issue Fixed!

Had to wrap my function with

if ( !function_exists( 'function_name' )) {
    function function_name() {
        //Stuffs
    }
}  

Perfect!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.