Categories
Code

How to turn off captions in WordPress 2.6

Having fun with new technology

Turn off da captions, turn off da funk!

I’ve found that many who found my previous article about removing caption from the All In One SEO Pack are interested in disabling the WordPress 2.6 captions altogether. This is very simple to do.

Futureproof way to disable captions

From Otto:

Add this to your theme’s functions.php file:
add_filter('disable_captions', create_function('$a','return true;'));

[Edited: Updated with final solution from Otto]. Thanks to King Rat and others who’ve contributed to solving this problem.

If you have any questions, revisions, or…comments, leave a comment!

By Zack Katz

Zack Katz is the founder of GravityKit and TrustedLogin. He lives in Leverett, Massachusetts with his wife Juniper.

38 replies on “How to turn off captions in WordPress 2.6”

A simpler way would be to just add this to your theme’s functions.php file:
function no_caption($deprecated, $attr, $content) { return $content };
add_filter(‘img_caption_shortcode’, ‘no_caption’, 10, 3);

Done and done. Captions off for good, unless they change them a bit more substantially than normal in future revisions.

Note that I haven’t actually tested that or anything. That’s code from the hip. 😉

Should work though, or be an extremely minor fix if it doesn’t.

Turn it off? I’m still trying to figure out how to make it work. Added all the code to my current theme but still nothing. Caption looks great in the edit pane, but code spills out when it goes live. If any of you can spot what I’m doing wrong, I’d love to hear it.

@LaFlamme — Make sure your CSS is in order. You’ll need to style the caption code. The captions have a class of wp-caption, and the caption itself is wp-caption-text.

Hope that helps.

Yeah, but that solution isn’t quite the same as what I’m interested in. I want to turn off the insertion of the [caption] code by the “insert image” code.

I want to have captions on images I choose. With 2.6 I have to insert image, remove caption for about 50% of the images, which is annoying.

@King Rat — That’s a seriously involved process that includes editing wp-admin/media.php. You’ll find that there are lots of little things that you would need to update, such as the Javascript (addExtImage) and each one of the many forms that are part of the upload form: from the web, from your computer, from the gallery, from your media library…

Let’s just hope that they add the functionality in WP 2.6.1, because to do it yourself is a royal pain.

Anyone else know how you might do it?

Didn’t work me, searched around google, and found this (did work):

define('CAPTIONS_OFF', true);

Just adding that instead to your functions.php file did the trick

@Ash – That is the temporary way of disabling captions that will not be allowed in future versions of WordPress (it says so right in the code not to use it).

If the other option didn’t work, then by all means use it, but be warned — the solution won’t last.

This broke wp-admin for me, it seems that a CSS solution is a more visible and reasonable way to deal with this — add to style.css:

.wp-caption-text {
display: none;
}

@c.urdaneta – It looks like you may be using curly quotes, which can happen if you copy and paste in the code. Make sure you’re using a single quote (I think they’re called a “prime”)…

Another option is you may be missing a few WordPress files. Try reinstalling 2.6, and make sure you delete the wp-admin and wp-includes folders completely before re-installing.

Try that, and if that doesn’t work, let me know again!

I found a way to do what I was looking for above. I made a simple plugin with the following code:

function rat_disable_captions ( $foo = ” ) {
return TRUE;
}

add_filter ( ‘disable_captions’ , ‘rat_disable_captions’ );

This works in 2.6.2. One line of code.

add_filter(‘disable_captions’, create_function(‘$a’,’return true;’));

That will prevent the caption code from being inserted into posts when you insert the image, prevent them from showing up, should be everything.

Hello,
is it possible if I want to disable caption only at my frontpage?

I’d like to manually style my post thumbnail (currently done using get-the-image plugin from Justin Tadlock), while removing the caption for the image used for the thumbnail. I still want the caption to be displayed in the single post page though..

Thank you.

@bimz – in your functions.php file, simply wrap the code with this:

Above the code:
if(is_home() || is_front_page()) {

Below the code:
}

This will make it so that the function only gets executed on the home page (or whatever page you’ve designated as the front page).

Hi guys,

I’m trying to remove the alt/title tags from the drop down menus on my wordpress navbar, ie. what’s happening now is the drop down menu is composed of image boxes… so when the user hovers their mouse over the drop down menu, the corresponding alt tag for the image pops up, and blocks the menu text below :S

Thanks in advance for any help!

Hi Guys,

none of these lines of code worked for me in 2.6.2 I don’t know what I’m supposed to wrap around that code…I assume a php tag?! I tried that and it didn’t get rid of my captions.

i’m no php coder..just front end coder. what else is missing to make this one line take out the caption in the functions.php file?

What I really want is for the caption only not to show up in the excerpts..

I’m not using the excerpt custom field, instead I’m using this in index.php to pull the first 600 words or so from each post…that way there is less work to do of picking an appropriate section to copy and paste to the excerpt field!

I’m using this code:


post_excerpt, 0, $len); //truncate excerpt according to $len
if(strlen($newExcerpt) post_excerpt)) {
$newExcerpt = $newExcerpt."[...]";
// get rid of the [caption]s
}
echo "".$newExcerpt.""; //finally display excerpt
?>

Can’t I just get the caption tag not to show up in that…I wish it would just display how it’s supposed to in a full blog post! as a caption!

Comments are closed.