Retrieve custom variable

The problem is that the $opt_val global variable is being set only when the my_plugin_options function is called. And that function is being called only in case user is viewing the My Plugin Options screen. You’ll have to call get_option( ‘mt_favorite_color’ ); inside the hook_css function. (Please note that the hook_css function is not being … Read more

Get current page id, title, url, etc

<?php $link = “https://wordpress.stackexchange.com/questions/25552/mailto:?subject=”. get_bloginfo() .” ‘. the_title_attribute(array(‘echo’=>0)); $link .= ‘&amp;body=some text ‘. get_permalink(); ?> <a href=”https://wordpress.stackexchange.com/questions/25552/<?php echo $link ?>”>mail to a friend</a>

What does the Global Variable $s represent?

It’s not a global variable; in fact it’s not a variable at all. It’s just placeholder within the sprintf() function. Take a look at the sprintf PHP function documentation. In the example you cite, the author is using the ‘argument swapping’ placeholder syntax: %n$t where %n is the placeholder number that corresponds to the argument … Read more

Passing a variable from a FOREACH loop in a link

This is more of a basic PHP question, but still it’s somewhat important. Inside your foreach loop, $category is a locally-defined variable. That’s to say, it only exists inside the foreach loop. So if you have foreach ( $categories as $category ) { // You can use $category all you want in here } // … Read more

What is the use of $content_width?

$content_width is used to set the default width of embeds, for situations when an element needed to specify a width. This is how WP knew the width of the main content area. However, this was back before the push for responsive design, and modern CSS with fluid embeds and responsive breakpoints. So it isn’t needed … Read more

How do I share variables between two functions?

Create a class to store the variables as private, internal members. Set up the variables when the post object is set up, that’s the action the_post. Then assign class methods as callbacks instead of separate functions. Here is your code slightly reformatted: The class class WPSE_WC_Badge { private $title=””; private $class=””; private $duration = ”; … Read more

Best way to pass variables around a WordPress site?

It is possible to do this using the function wp_get_current_user(). This function will get the contents of the WP_User class. It can be stored in a global variable: global $current_user; $current_user = wp_get_current_user(); $current_user will then become an array matching the properties of WP_User for the currently logged in user. If no user is logged … Read more

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