Append HTML Using Shortcode

First things first. You shouldn’t really use echo inside a shortcode, unless there is NO way to return the value. In your case your can simply convert it to a function that returns a value: function date_important_info(){ return display_date($date); function display_date($date){ $data = ” <div id=’my-shortcode’ style=””> <span>Date:</span> <span> {$date} </span> </div>”; return $data; } … Read more

How to query for posts with a null or blank post_name?

If you want to use WP_Query: $no_title_posts = new WP_Query(array(‘name’=>”,’posts_per_page’=>-1); That will search all posts with empty name. The posts_per_page = “-1” returns all posts because by default wp returns 10 or whatever number you have selected in your admin settings. if you want to retrieve it from other posts types (default is “post”), then … Read more

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