1

I want to pass my google map custom colors from my child theme to my parent theme.

So in my Parent Theme's functions.php I have

add_filter( 'post_thumbnail_html', "map_thumbnail" );
function map_thumbnail($html, $color1, $color2) {
       $my_post = get_post($post->ID);
       $water_color=$color1;
       $tree_color=$color2;
       if($my_post->post_name == "contact") {
       $html = '<img height="100%" width="100%" src="http://maps.googleapis.com/maps/api/staticmap?watercolor='.$water_color.'treecolor='.$tree_color.'">';
       }
return $html;
}

I just want to pass two colors from my child theme's functions.php like so,

$color1 = '#fb0000';
$color2 = '#c0e8e8';
apply_filters('post_thumbnail_html', $color1, $color2);

But unfortunately this is not working. Can anyone help me out here ? I have 3 child themes and all of them have the same map, just the tree color and water color are different. I want to keep the main map_thumbnail function in the parent theme and pass only the individual colors from my child themes. Please help me out if possible.

2 Answers 2

3

Stick to filtering one value at a time to keep it simple, and add filters for the colors to be used by the child theme:

add_filter( 'post_thumbnail_html', 'map_thumbnail');
function map_thumbnail($html) {
   $my_post = get_post($post->ID);
   $defaultcolor1 = "#??????"; // parent theme default
   $defaultcolor2 = "#??????"; // parent theme default
   $water_color = apply_filters('water_color',$defaultcolor1);
   $tree_color = apply_filters('tree_color',$defaultcolor2);
   if($my_post->post_name == "contact") {
       $html = '<img height="100%" width="100%" src="http://maps.googleapis.com/maps/api/staticmap?watercolor='.$water_color.'treecolor='.$tree_color.'">';  
   }
   return $html;
}

So in the child theme you can use:

add_filter('water_color','custom_water_color');
add_filter('tree_color','custom_tree_color');

function custom_water_color() {return '#fb0000';}
function custom_tree_color() {return '#c0e8e8';}
1
  • worked so nicely...thanks a lot man...cheers...take care
    – Saif Islam
    Commented Mar 9, 2016 at 15:58
0

Without having tried it myself I would suggest you write a small function for your child theme and then call the parent's theme funstion like this:

add_filter( 'post_thumbnail_html', "child_map_thumbnail", 11 );

function child_map_thumbnail($html) {

    $color1 = '#fb0000';
    $color2 = '#c0e8e8';

    map_thumbnail($html, $color1, $color2);

    return $html;

}

As I said: I haven't tried this myself – but I suppose the function of your parent theme should be available – so basically my suggestion would be to call that function instead of passing variables… 

2
  • sorry man, doesn't work...thanks for the idea though...cheers
    – Saif Islam
    Commented Mar 9, 2016 at 15:58
  • 1
    yup – Thanks for the reply and the edit… Interesting question anyways – bookmarked it… cheers… Commented Mar 9, 2016 at 21:36

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.