Skip to main content
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
deleted 7 characters in body
Source Link
cjbj
  • 15k
  • 16
  • 42
  • 89

I want to pass a variable from my child theme function to a filter which resides in my parent theme. Please let me know whether below code will work or not ? Is it the right way ?

Code in Parent Theme's functions.php

add_filter( 'post_thumbnail_html', "map_thumbnail" );
function map_thumbnail($html,$color) {
        $my_post = get_post($post->ID);
        $my_color = $color;
        if($my_post->post_name == "contact") {
              $html = '<img src="http://maps.googleapis.com/maps/api/staticmap?color:$my_color">';
        }
        return $html;
}

Code in Child Theme's functions.php

<?php map_thumbnail('#0099dd'); ?>

Please tell me, will my above code work  ? Can I pass the variable $color value$color from my child theme to parent theme like this ?

I want to pass a variable from my child theme function to a filter which resides in my parent theme. Please let me know whether below code will work or not ? Is it the right way ?

Code in Parent Theme's functions.php

add_filter( 'post_thumbnail_html', "map_thumbnail" );
function map_thumbnail($html,$color) {
        $my_post = get_post($post->ID);
        $my_color = $color;
        if($my_post->post_name == "contact") {
              $html = '<img src="http://maps.googleapis.com/maps/api/staticmap?color:$my_color">';
        }
        return $html;
}

Code in Child Theme's functions.php

<?php map_thumbnail('#0099dd'); ?>

Please tell me will my above code work  ? Can I pass the variable $color value from my child theme to parent theme like this ?

I want to pass a variable from my child theme function to a filter which resides in my parent theme. Please let me know whether below code will work or not ? Is it the right way ?

Code in Parent Theme's functions.php

add_filter( 'post_thumbnail_html', "map_thumbnail" );
function map_thumbnail($html,$color) {
        $my_post = get_post($post->ID);
        $my_color = $color;
        if($my_post->post_name == "contact") {
              $html = '<img src="http://maps.googleapis.com/maps/api/staticmap?color:$my_color">';
        }
        return $html;
}

Code in Child Theme's functions.php

<?php map_thumbnail('#0099dd'); ?>

Please tell me, will above code work? Can I pass the variable $color from my child theme to parent theme like this ?

Source Link

Passing variable from child theme function to parent theme filter

I want to pass a variable from my child theme function to a filter which resides in my parent theme. Please let me know whether below code will work or not ? Is it the right way ?

Code in Parent Theme's functions.php

add_filter( 'post_thumbnail_html', "map_thumbnail" );
function map_thumbnail($html,$color) {
        $my_post = get_post($post->ID);
        $my_color = $color;
        if($my_post->post_name == "contact") {
              $html = '<img src="http://maps.googleapis.com/maps/api/staticmap?color:$my_color">';
        }
        return $html;
}

Code in Child Theme's functions.php

<?php map_thumbnail('#0099dd'); ?>

Please tell me will my above code work ? Can I pass the variable $color value from my child theme to parent theme like this ?