Static variable and add_rewrite_rule?

You can’t add arbitrary query variables to the rewrite rules, there’s a whitelist of allowed variables. To add a query variable, use query_vars filter, e.g. this filter adds my-api as a valid query variable: function wpd_query_vars( $query_vars ){ $query_vars[] = ‘my-api’; return $query_vars; } add_filter( ‘query_vars’, ‘wpd_query_vars’ ); But that just gets you the query … Read more

Displaying the Month and Year that a page was Created?

This worked for me. I created variables for both the month of the post and the year of the post. <?php $post_month = get_the_time(‘F’); $post_year = get_the_time(‘Y’); if ( is_page(‘about/mission-statement/’)) { echo ‘<time>’ . $post_month . ‘ ‘ . $post_year . ‘:’ . ‘</time>’; } ?>

Where to edit the template that is generating the code for dynamic_sidebar left-sidebar in the Understrap theme? [closed]

Dynamic_sidebar pulls whatever widgets are assigned to that sidebar. If you want to add a class for the whole sidebar, surround the call in a div that you can then assign classes. <?php if ( is_active_sidebar( ‘left-sidebar’ ) ) : ?> <div class=”sideclass”> <?php dynamic_sidebar( ‘left-sidebar’ ); ?> </div> <?php endif; ?>

Using $_GET in Functions.php [closed]

Not really a WordPress related question, but the answer is fairly simple. When you try to call an element of a array that doesn’t exist, you will get an undefined index error, since it simply doesn’t exist. $_GET is a superglobal array, so this is the case. To fix this issue, you should first check … Read more

How to display to visitor which site they came from?

WordPress has a function that can extract referrer information (website where user originated from): wp_get_referer(). It will return URL from the originating website. If that is not available it will return FALSE. This is the simple example PHP function that will display welcome message when called, if the referrer is set: function wse_280729_show_welcome_message() { $ref … Read more

Getting array of customizer settings

Yes. You can get an array of all registered settings via $wp_customize->settings(). If you want to display them all you could do this: if ( is_customize_preview() ) { global $wp_customize; $theme_mods = array(); foreach ( $wp_customize->settings() as $setting ) { if ( ‘theme_mod’ === $setting->type ) { $theme_mods[ $setting->id ] = $setting->value(); } } echo … Read more

How can i upload images in an admin page?

First of all edit_user_profile and show_user_profile action hooks don’t have to save the image, you can just add a field there. So function image_up_gall(){ ?> Select image to upload: <input type=”file” name=”fileToUpload” id=”fileToUpload”> <input type=”submit” value=”Upload Image” name=”submit”> <?php } add_action(‘edit_user_profile’, ‘image_up_gall’); add_action(‘show_user_profile’, ‘image_up_gall’); It is because WordPress has its own form tag already, just … Read more