How to limit post content and remove image caption from it

Image captions in WordPress are actually shortcodes. Shortcodes are applied by the filter: $content = apply_filters(‘the_content’, $content); For example, WordPress creates the following code in your content when you enter an image caption: You need to still use apply_filters() in order to properly display content. (safe content display and all other shortcodes) If you don’t … Read more

Caption in Page adding unwanted 10px to width

Here’s what you can do. There’s a filter at the beginning of the shortcode execution function for the front end that will let you hijack the captions. Returning a non-empty value will stop execution of the shortcode, so if you just process the shortcode the way you want it to be processed and return that … Read more

How to display a shortcode caption somewhere other than the_content

Try this: $caption_info = array(); add_filter( ‘img_caption_shortcode’, ‘capture_caption’, 10, 3 ); function capture_caption( $blank = ”, $attr, $content ) { global $caption_info; $caption_info[] = array(‘attr’ => $attr, ‘content’ => $content ); return ‘ ‘; } It will save info from all captions into global $caption_info variable and suppress their display in content (space is returned … Read more

Alter media caption/description conflict in WordPress?

I wonder if this will work for you: add_action( ‘add_attachment’, function( $attachment_id ){ $a = get_post( $attachment_id ); if ( is_object( $a ) && ‘image’ === substr( $a->post_mime_type, 0, 5 ) ) wp_insert_attachment( array( ‘ID’ => $a->ID, ‘post_excerpt’ => $a->post_content ) ); }); or with less queries: add_action( ‘add_attachment’, function( $attachment_id ){ global $wpdb; if( … Read more

Is there a way to define a default caption to all uploaded images

There’s really no documentation for it yet, but you’ll probably be able to do it hooking to the attachment_fields_to_save filter and inserting the default caption there. From the Codex: attachment_fields_to_save applied to fields associated with an attachment prior to saving them in the database. Called in the media_upload_form_handler function. Filter function arguments: an array of … Read more

How I can get image description/title/alt for gallery image?

You need to get the metadata of each image, add this to your functions.php file: function get_post_gallery_images_with_info($postvar = NULL) { if(!isset($postvar)){ global $post; $postvar = $post;//if the param wasnt sent } $post_content = $postvar->post_content; preg_match(‘/\[gallery.*ids=.(.*).\]/’, $post_content, $ids); $images_id = explode(“,”, $ids[1]); //we get the list of IDs of the gallery as an Array $image_gallery_with_info = … Read more

How to wrap WordPress image captions inside H2, H3 tags?

You can hook into the filter img_caption_shortcode and replace the whole captioned image. Here I’ve copied the caption shortcode function from WP4.5, left the version used if your theme declares HTML5 support as it is (using figcaption) and modified the non-HTML5 version to use h2. function wpse_233354_img_caption_shortcode( $empty, $attr, $content = null ) { // … Read more

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