Tag Info

Hot answers tagged

4

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 result, you can get rid of the pesky 10px of inline ...


3

I'm glad that better support should be added in version 3.4 but for now I've fixed the issue by changing the behaviour of image insertion so that it doesn't use the [caption] shortcode. Here's what I added to functions.php: add_filter( 'disable_captions', create_function('$a', 'return true;') ); function image_send_to_editor_2($html, $id, $caption, ...


3

That caption shortcode is built into WordPress. It should generate the same markup for any theme, unless the theme or a plugin has unregistered it and registered a replacement. I don't know if that is the case with your theme or with TwentyEleven. Look for 'img_caption_shortcode' in your theme files, probably functions.php. If your theme is unregistering it, ...


3

Another possibility is to change the shortcode output so that the width is no longer hard-coded. Modifying the Codex example to have no width: add_filter('img_caption_shortcode', 'my_img_caption_shortcode_filter',10,3); /** * Filter to replace the [caption] shortcode text with HTML5 compliant code * * @return text HTML content describing embedded ...


2

There is a hook inside the caption shortcode that will allow you to hijack the whole thing. Most of the following is copied from the Core img_caption_shortcode function. function nested_img_caption_shortcode($nada, $attr, $content = null) { extract( shortcode_atts( array( 'id' => '', 'align' => 'alignnone', 'width' ...


2

st Note: // Prepare the code for safety $images = $wpdb->get_col( $wpdb->prepare( " SELECT ID FROM %s WHERE post_type = 'attachment' AND ID IN ( %s ) ORDER BY menu_order ASC ", $wpdb->posts, $meta ) ); nd Note: Look into what you already got: // Inside the foreach loop echo '<pre>'; var_dump( $att ); echo '<pre>'; rd ...


2

Adapted from this answer Add this code to your functions.php file: add_action( 'after_setup_theme', 'wpse_74735_replace_wp_caption_shortcode' ); /** * Replace the default caption shortcode handler. * * @return void */ function wpse_74735_replace_wp_caption_shortcode() { remove_shortcode( 'caption', 'img_caption_shortcode' ); ...


2

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. ...


2

Have you tried this for NextGen? - http://wordpress.org/support/topic/nextgen-image-gallery-captions Excerpt (many other useful tips at the linked thread): ENABLING CAPTIONS BELOW GALLERY IMAGES When you add a gallery to a post/page, you get this by default: [nggallery id=1] You need to add this: [nggallery id=1 template=caption] ...


2

To use this you will need to add this to in place of your themes thumbnail function: function your_thumbnail_caption($html, $post_id, $post_thumbnail_id, $size, $attr) { $attachment =& get_post($post_thumbnail_id); if ($attachment->post_excerpt || $attachment->post_content) { $html .= '<p class="thumbcaption">'; if ...


2

Yes, it stores the caption in it's own place in the DB. I can't quote the exact location but in Wordpress, "Attachments" are a post type and it stores each attachment just like a post. For an attachment post type, it treats the Image Caption as the_excerpt the Image Description as the_content and the Image Title as... the_title.


2

Your problem is with your foreach loops... here: if ($images) { foreach($images as $image) { $caption = $image->post_excerpt; } } and here: //alt title foreach ($images as $attachment_id => $image) { $img_alt = get_post_meta($attachment_id, '_wp_attachment_image_alt', true); } Basically what is happening is that your ...


1

the following should just show the caption: echo '<div class="slideshow-content"><img src="'.wp_get_attachment_url($attachment->ID, 'thumbnail', false, false).'" /><div class="captions">'.apply_filters('the_excerpt', $attachment->post_excerpt).'</div></div>'; (applying the excerpt filter adds the paragraph tag ...


1

Use this to check the first letter of each word - if(ucwords($name) === $name) : { First letter is capitalised } else : $name = ucwords($name); endif; Or you can use ucfirst() for only the first letter of the field. If you know for sure that you wan't it in upercase though, you don't have to worry about the check, just run do $name = ...


1

I'd not use something like this at all. There are plenty of hooks for content and excerpt retrieval to use, I see absolutely no need to drop native functions in favor of something else. You can use excerpt_length filter to change excerpt length (in words) or the_excerpt to make changes to excerpt's text before output. If I may ask - what is your technical ...


1

As far as I know the only way to add styles to RSS feed items is by adding them inline (e.g. <p style="color: #333; font-weight: bold;">Hello World</p>). If you don't specify any styling, then the reader app/website that the end-user is using applies its default styles. Certainly editing styles.css won't make any difference, because that files ...


1

At this point in time I would just as soon not use the More Fields plugin at all, as there are native functions that can do everything you probably want with custom fields. There seems to be no good documentation afoot and the plugin site is obviously not being updated. Alternatively, try WPAlchemy. Quite easy to make discrete meta boxes with multiple form ...


1

I don't think you can do that, however you can implement this code in your functions file to at least allow for line breaks in single image captions Note: doesn't work for gallery images (I am trying to find a way to make it work in galleries) /* ********************************************* Function to allow multi-line photo captions. This function will ...


1

Here is an example below where you can embed html tags within the Caption box and it will style your caption text accordingly. Also, don't forget that WordPress applies a default class of wp-caption to your caption elements for which you can further use to specify custom CSS properties, so technically you can wrap text within your caption box also using ...


1

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: [caption id="attachment_55" align="alignleft" width="127" caption="Here is my caption"][/caption] You need to ...


1

Find the line /* Remove [caption] in-line styling in function.php. Comment out: /* add_shortcode('wp_caption', 'fixed_img_caption_shortcode'); add_shortcode('caption', 'fixed_img_caption_shortcode'); function fixed_img_caption_shortcode($attr, $content = null) { // Allow plugins/themes to override the default caption template. $output = ...


1

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 ...


1

Can you try something along these lines and report back the result? <?php if(qtrans_getLanguage()=='en'): ?> // attachment if statement <?php else if(qtrans_getLanguage()=='fr'): ?> // attachment if statement <?php endif; ?> Technically you could omit the second else if statement and replace it just with <?php else : ?> ...


1

You need only a regex to catch the class from content, check if the class for you size is one of the assigned class and if so add to output, something like: function my_custom_img_caption_shortcode($a, $attr, $content = null) { extract( shortcode_atts( array( 'id' => '', 'align' => 'alignnone', 'width' => '', 'caption' => '' ), $attr) ...


1

function wp_get_attachment( $attachment_id ) { $attachment = get_post( $attachment_id ); return array( 'alt' => get_post_meta( $attachment->ID, '_wp_attachment_image_alt', true ), 'caption' => $attachment->post_excerpt, 'description' => $attachment->post_content, 'href' => get_permalink( $attachment->ID ), 'src' ...


1

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: ...


1

WordPress stores image (attachment) data as follows: Description: post_content field Caption: post_excerpt field Alt: _wp_attachment_image_alt meta value And in code, that translates to: // Description echo $post->post_content; // Raw the_content(); // Caption (description as fallback) the_excerpt(); // Caption (explicitly) echo ...


1

First of all I don't think that create a custom post type only for backgrounds is a right choose: backgrond are images and images already have their post type: attachment. If you have Worpress 3.5+ you can register a custom taxonomy for attachments, call it, e.g. 'image_scope' : register_taxonomy('image_scope', 'attachment', $args ); for the $args array ...


1

Using latest function has_shortcode() introduced on v3.6 add_filter( 'the_content', 'process_wp_caption_shortcodes' ); // hook it late function process_wp_caption_shortcodes( $content ){ if( !function_exists ( 'has_shortcode' ) ) // no luck for user using older versions :) return $content; if( has_shortcode( ...


1

I know this is kind of primitive, but if all you really need to do is keep them from editing the caption when they hit ADD MEDIA you can just paste this into your functions.php add_action('admin_head', 'disable_caption_editing'); function disable_caption_editing() { echo "<style>.setting[data-setting='caption'] { display: none; }</style>"; } ...



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