WordPress Theme variables scope

I need to create a variable that can be accessed throughout my WordPress Theme template files (index.php, header.php etc..). I know function definitions go inside the functions.php template file (in your theme path), but there’s no such thing for variables. For example I constantly need to retrieve Categories in my Theme, so I would like … Read more

What is $post_id? is it a global variable in WordPress?

How can $post_id be used while echoing posts in single.php? Is it a global variable? 3 s 3 No, $post_id is not a global variable. You can see a list of global variables WordPress creates here: https://codex.wordpress.org/Global_Variables $post_id is just a common naming convention for a variable that contains a post ID. In tutorials and … Read more

What is a good alternative to using $content_width for image optimization?

The $content_width GLOBAL in WordPress effects many themes and even some plugins by limiting the size of images and embeds in posts, it is a requirement for themes submitted to wordpress.org. It is set by using: $content_width = 584; // Twenty Twelve example If you insert a large image (default 1024×1024) into a post it … Read more

How to pass arguments from add_settings_field() to the callback function?

I have a function like this: add_settings_field( ‘contact_phone’, ‘Contact Phone’, ‘settings_callback’, ‘general’); That works. It calls settings_callback. Cool. The problem I have with this is: I don’t want to have to define a callback function for every setting I add, if all I’m doing is echoing out a little bit of stuff. function settings_callback() { … Read more

How to set and use global variables? Or why not to use them at all

UPDATE: My original question has been solved, but this is turning into a valid discussion about why not to use global variables, so I am updating the question to reflect that. The solution was <?php global $category_link_prop; echo esc_url( $category_link_prop ); ?> as @TomJNowell suggested. UPDATE 2: I now have it doing exactly what I … Read more