Adding variable to get_template_part

It looks like you’re just trying to concatenate a string, so it can be done like this: <?php get_template_part( ‘template-parts/component-page/component-‘ . $variable ); ?> Or you could use string interpolation (note the double quotes used here): <?php get_template_part( “template-parts/component-page/component-{$variable}” ); ?> Alternatively, get_template_part() can take two parameters, $slug and $name: <?php get_template_part( ‘template-parts/component-page/component’, $variable ); … Read more

What is the $current_screen global variable?

$current_screen is a global variable in admin screens. It holds the result of WP_Screen::get( $hook_name )->set_current_screen();. WP_Screen is a class, get() is a static method that returns a real object – an instance of WP_Screen with some predefined properties: $screen->base = $base; $screen->action = $action; $screen->post_type = (string) $post_type; $screen->taxonomy = (string) $taxonomy; $screen->is_user = … Read more

where to include a php file

Variables have a certain scope. The PHP Manual explains that in detail. So when you set a variable you should know in which scope those are set. This depends on where you set them and how that file gets included. As Rarst already suggested, the function.php file is an ideal place as it gets included … Read more

How to make variables in URL look like the permalink structure?

The following two functions should point you in the right direction: function wpse49393_query_vars($query_vars) { $query_vars[] = ‘myvar’; return $query_vars; } add_filter(‘query_vars’, ‘wpse49393_query_vars’); function wpse49393_rewrite_rules_array($rewrite_rules) { $rewrite_rules[‘path/to/page/([^/]+)/?$’] = ‘index.php?pagename=path/to/page&myvar=$matches[1]’; return $rewrite_rules; } add_filter(‘rewrite_rules_array’, ‘wpse49393_rewrite_rules_array’); I would give credit where it is due, but I cannot remember where I originally found this code. I just pulled this … Read more

How to tell if $query_var isset?

use the indentical comparison operator: if(get_query_var(‘cls’) !== ” && get_query_var(‘ch’) !== ”) { mcs_textbook_chapter($dialect, $cls, $ch); } elseif(get_query_var(‘cls’) !== ”) { mcs_textbook_chapter($dialect, $cls); } else { mcs_textbook($dialect); }

Get ACF value in external jQuery document

Your question is not entirely clear, but it looks like you are in need of wp_localize_script, which allows you to pass variables from PHP to a script. You would use it like this (example with two fields): add_action (‘wp_enqueue_scripts’,’wpse244551_add_field’); function wpse244551_add_field () { $my_field = array (); $my_field[] = array (field1 => get_field (‘field1’)); $my_field[] … Read more

Using variable in two functions

As a matter of good coding practice, global variables are problematic at best, dangerous at worst. They should be avoided if at all possible. Why? Because what if some other plugin developer also decides to define$a as a global? Whatever that plugin is doing will now overwrite your global $a and yours has the potential … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)