What kind of object type is WP_Query?

I’m not sure you understand the logic of WP_Query. Rather than explain in words, here’s a code example; $query = new WP_Query( array( ‘meta_key’ => ‘Old ID’, ‘meta_value’ => $atts[‘oldid’] ) ); if ( $query->have_posts() ) return $query->posts[0]->post_title; return ”; Check out the codex on interacting with WP_Query. UPDATE: To use the query as you … Read more

Show content only if member left a comment

Check if the user has left a comment // the user may have commented on *any* post define( ‘CHECK_GLOBAL_FOR_COMMENTS’, TRUE ); // // some more code // function memberviparea( $atts, $content = null ) { $post_id = 0; // if the user have to left a comment explicit on this post, get the post ID … Read more

Enqueue script only when shortcode is used, with WP Plugin Boilerplate

Why it’s not working: You need to use the wp_enqueue_scripts action hook. You’ve used wp_register_script as an action hook, however, there is no action hook named wp_register_script in WordPress core. If this was just a silly mistake, then you already have the answer. Read on if you need more information regarding the topic: Attaching a … Read more

How to add attributes to a shortcode

You just have to add another element to the array (and then output it): function btn_shortcode( $atts, $content = null ) { $a = shortcode_atts( array( ‘class’ => ‘button’, ‘href’ => ‘#’ ), $atts ); return ‘<a class=”‘ . esc_attr($a[‘class’]) . ‘” href=”‘ . esc_attr($a[‘href’]) . ‘”>’ . $content . ‘</a>’; } add_shortcode( ‘button’, ‘btn_shortcode’ … Read more

How to detect if a Shortcode is being called on a page?

I have sometimes wondered the same thing – whether wp maybe checked on save and kept a register etc I had a quick look at the code, and it seems not. There is however a global $shortcode_tags, and wp has this function function get_shortcode_regex() { global $shortcode_tags; $tagnames = array_keys($shortcode_tags); $tagregexp = join( ‘|’, array_map(‘preg_quote’, … Read more

Organizing shortcodes. How to display all of them and their attributes?

Inspect the global variable $shortcode_tags: print ‘<pre>’ . htmlspecialchars( print_r( $GLOBALS[‘shortcode_tags’], TRUE ) ) . ‘</pre>’; Output: Array ( => img_caption_shortcode => img_caption_shortcode => gallery_shortcode => __return_false [contactform] => Array ( [0] => T5_Contact_Form Object ( [debug:protected] => [base_name:protected] => t5-contact-form/t5-contact-form.php [prefix:protected] => t5c [address:protected] => [nonce_name:protected] => t5_contact_form_nonce [hidden_field:protected] => t5_no_fill [option_name:protected] => t5c_default_address … Read more

Always use for post images

You can try the image_send_to_editor filter: /** * Wrap the inserted image html with <figure> * if the theme supports html5 and the current image has no caption: */ add_filter( ‘image_send_to_editor’, function( $html, $id, $caption, $title, $align, $url, $size, $alt ) { if( current_theme_supports( ‘html5’ ) && ! $caption ) $html = sprintf( ‘<figure>%s</figure>’, $html … Read more

enqueue script for specific shortcode

wp_enqueue_script is not going to work in a shortcode, this is because of the loading order. You could use wp_register_script and then you could wp_enqueue_script in you shortcode function like this example: // Front-end function front_end_scripts() { wp_register_script( ‘example-js’, ‘//example.com/shared-web/js/example.js’, array(), null, true ); } add_action( ‘wp_enqueue_scripts’, ‘front_end_scripts’ ); Then you use this in your … Read more

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