Modify how gallery.js builds the shortcode [gallery ...] in tinyMCE?
Modify how gallery.js builds the shortcode in tinyMCE?
Modify how gallery.js builds the shortcode in tinyMCE?
I just fixed this after several hours of research. If one need to do the same thing, he must edit file wp-includes\js\media-views.js and replace add with unshift in this line (#2611, galleryAddToolbar): edit.get(‘library’).add( state.get(‘selection’).models ); So the code will look like this: edit.get(‘library’).unshift( state.get(‘selection’).models ); After that when you add images in the gallery they … Read more
You can filter the default gallery shortcode. Here is something I’ve used in the past. add_filter( ‘post_gallery’, ‘wpse_gallery’, 10, 2 ); function wpse_gallery() { global $post; /* Orderby */ if ( isset( $attr[‘orderby’] ) ) : $attr[‘orderby’] = sanitize_sql_orderby( $attr[‘orderby’] ); if ( !$attr[‘orderby’] ) unset( $attr[‘orderby’] ); endif; /* * Extract default gallery settings … Read more
UPDATE I’ve just submitted a core patch to add link=”none” support to the shortcode. ORIGINAL ANSWER You don’t need to hack core to do what you want to do; just use the appropriate shortcode parameters, e.g.: If you want to change the defaults, then use the post_gallery filter: function mytheme_gallery_shortcode_defaults( $output, $attr ) { global … Read more
Gallery Image Caption – As Title Of The Post It’s attached To Here’s one way to do it with a custom parent_titles attribute in the native gallery shortcode. This can be achieved by setting suppress_filters to false for the gallery query and modify the posts excerpts through the the_posts filter. We can then check for … Read more
Add filter is not intended to replace fully the existing code, but rather to append it. In the case of post_gallery, if you return ANYTHING but ”, it will not do ANY of the default action. If you look on line 767 of /wp-includes/media.php, you can see where the hook is applied and work around … Read more
Instead of using 2 separate functions to grab the attachment you can use the same function, and then add the URL in separately using wp_get_attachment_url, making the logic much clearer, and reducing the amount of work needed: e.g. $image = wp_get_attachment_image( $id, $size, false ); // if it’s set to not show the image link … Read more
Here are the functions you need to be aware of: http://codex.wordpress.org/Function_Reference/get_post_thumbnail_id http://codex.wordpress.org/Function_Reference/wp_get_attachment_url http://codex.wordpress.org/Function_Reference/wp_get_attachment_image_src http://codex.wordpress.org/Function_Reference/wp_get_attachment_image Example sans size: echo wp_get_attachment_url(get_post_thumbnail_id()); Example with size: $image = wp_get_attachment_image_src(get_post_thumbnail_id(), ‘large’); echo $image[0]; //as HREF in your A tag You can grab all of the gallery images as follows: $args = array( ‘order’=> ‘ASC’, ‘post_mime_type’ => ‘image’, ‘post_parent’ => $post->ID, … Read more
When WordPress displays post content, it’s not running do_shortcode() on the post content, it’s running apply_filters( ‘the_content’, $content ). Shortcode filters are applied on the_content filter, which is why you have to add extra filters to get them to work in widgets or the footer or elsewhere.
WordPress has a native function wp_mime_type_icon() in wp-includes/post.php that you can use. Basic example: // $attachment should be a full post object if ( wp_attachment_is_image( $attachment->ID ) ) { echo wp_get_attachment_image( $attachment->ID, array( 480, 900 ), FALSE, array ( ‘class’ => ‘aligncenter’ ) ); } else { echo ‘<img src=”‘ . wp_mime_type_icon( $attachment->post_mime_type ) . … Read more