Tag Info

Hot answers tagged

5

I am not sure why your query is returning more IDs than necessary. The $args for get_users look correct. By default get_users does not support orderby=rand, but you can overwrite that option. See below: function random_user_query( &$query ) { $query->query_orderby = "ORDER BY RAND()"; } // Usage: [random_users how_many = 3] add_shortcode( ...


3

Try this. Add the code below to your functions.php file - add_shortcode('cat_description', 'my_cat_description_shortcode'); function my_cat_description_shortcode($atts){ $a = shortcode_atts( array( 'id' => 0, ), $atts ); return category_description($a['id']); } Should you wish to call the shortcode from a template (unnecessary ...


2

I believe the real issue you had was with echoing your data instead of returning it. A shortcode should return the output to be drawn, which is then drawn in place of the short code. Here is the code using HEREDOC syntax for outputs and the query. I believe this makes things much more readable once you get used to it. See ...


2

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' ) && ! ...


2

QUESTION AND ANSWER REVISITED There are sometimes these questions that nags you and hunts you down later in life again, and this is one such question. This question had me thinking about an alternative solution to the problem. As I already stated, custom fields and meta boxes are there to store small pieces of meta data, and not to act as an extension to ...


1

I think you just forgot to run the shortcodes [foo a='b'] and [bar a='c'] through the do_shortcode filter: do_shortcode( '[foo a='b'] [bar a='c']' ) The output of the_content() is filtered through the do_shortcode, so you can just add it into your editor instead. Running your code I get the following output for the $arguments dump: array (size=1) 'a' ...


1

Shortcode callbacks get a third argument with the shortcode name. there's a note about this in the docs: Appears to always appear as third argument as of 2.9.2. add_shortcode('foo', 'wpse173855_shortcode'); add_shortcode('bar', 'wpse173855_shortcode'); function wpse173855_shortcode($atts, $content, $name) { echo '<pre>'; var_dump($name); ...


1

No, there is no core shortcode for this. The site name is available as an option, in facts get_option('blogname') returns the blog name. Moreover, get_bloginfo('name') / bloginfo('name') can be used to get / echo the site name. Of course, you can't use that functions as a shortcode by default, so if you want to obtain that, and you don't want to edit ...


1

An alternative you have not mentioned is to customize the shortcode experience, since shortcodes are a UX failure for the end user. Create a specific shortcode button on the editor so the user can select text and click an actual button. You can go further and attach some code to error check what the user selects or ask if the selected text is correct. ...


1

This might help. On the YouTube video page, choose Share, then choose Embed, then choose Show More. Remove checks in boxes for "Show Player controls" and "Show Video Title and Player Actions." Choose largest given width size or custom size that is equal to or slightly greater than your div container width. Copy the code. Paste the code into your post, ...


1

You can use "rilwis/meta-box " for this . For dynamic slider use this snippet, <?php $images = rwmb_meta( 'gallery', 'type=image' ); foreach ( $images as $image ) { echo "<a href='{$image['']}' title='{$image['title']}' rel='thickbox'><img src='{$image['full_url']}' alt='{$image['alt']}' /></a>"; } ...


1

You could try mashing all the patterns together in one big regexp or and then doing a simple line by line parse of the content: function theme_oembed_videos() { global $post; if ( $post && $post->post_content ) { global $shortcode_tags; // Make a copy of global shortcode tags - we'll temporarily overwrite it. ...


1

You can use the pre_post_update filter hook to achieve this. Unfortunately the Codex isn't very good for this hook, but it's a simple enough one to understand and can be found in wp-includes/post.php on line 3335 (WP 4.1). add_filter( 'pre_post_update', 'my_replace_shortcode', 2, 99 ); function my_replace_shortcode( $post_id, $data ){ ...



Only top voted, non community-wiki answers of a minimum length are eligible