How to filter part of a variable if it is no array?

The documentation is well explicable of the topic, let’s have a look here https://developer.wordpress.org/reference/functions/apply_filters/. In your specific case my_filter is applied no matter what, even if there is no value it. To apply the filter only if is_array() you could insert a specific instruction directly into your filter like: function example_callback( $output ) { if(is_array($output)){ … Read more

add variable to actions/functions across different files (woocommerce)

Not really. Anything that loads a template in WordPress is ultimately an include() or require() and only the variables in the caller function scope (and global scope of course) are passed on to the included file: function foo() { $bar = 1; include( ‘/path/to/template.php’ ); } $baz = 2; foo(); // template.php: echo $bar; // … Read more

Import and use a variable in additional settings of Contact Form 7 [closed]

if only the domain changes, you could try using relative urls: document.location=”/thank-you”; But if the domain you’re redirecting to is different than the page you’re on, a simple way to fix this problem would be to add a customizer value redirect_domain, and then make it a global variable in footer.php <script>var RedirectUrl=<?php echo get_theme_mod(redirect_domain);?></script> then … Read more

Trying to get this function to show below the content

If it was me I’d not echo the text I’d make it a variable e.g. $additional_text = “” then at the end of the function return $additional_text;. if (have_posts()) : while (have_posts()) : the_post(); $additional_text=”<div class=”timeline”>”; $additional_text .= ‘<a href=”‘; $additional_text .= the_permalink(); $additional_text .= ‘”><h3>’; $additional_text .= the_title(); $additional_text .= ‘</h3></a>’; $additional_text .= ‘</div>’; … Read more

WordPress loop put title into variable

Creating variables on the fly like that is not needed. Just use an array instead. $myvars = []; inside your foreach loop you can: $myvars[] = array(‘title’=>$t,’image’=>$v); After your loop you can: //First title, First image echo $myvars[0][‘title’]; echo $myvars[0][‘image’]; //Second title, Second image echo $myvars[1][‘title’]; echo $myvars[1][‘image’]; This way you can always print_r($myvars) and … Read more

Product atributes in title of order (not in description)

This requires a little bit of code to be placed in functions.php. If you want you can use a plugin like WP-Designer to do that. The WooCommerce filter ‘woocommerce_product_variation_title’ uses 4 arguments which are self-explanatory in the following piece of code which you can use in you functions.php. I tried it on my install and … Read more

PHP Use Declared array Variable inside already Declared Array

This is more a generic PHP question than anything to do with WordPress, but I’d suggest setting the value in the constructor: class test { public $basicCols; public $optList = array( ‘one’ => ‘One’, ‘two’ => ‘Two’ ); function __construct() { $this->basicCols = array( array( ‘title’ => ‘KEY’, ‘field’ => ‘slug’, ‘options’ => $this->optList ), … Read more