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!
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.
@Otto — Thanks, I knew someone would have the “futureproof” way to do this.
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 iswp-caption-text
.Hope that helps.
Whoops. Add a ; after the return $content bit.
LaFlamme’s issue turned out to be the Max Banner Ads plugin. That breaks captions for some reason.
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.
[…] Alt-Angabe manuell befüllt werden. Zwar existiert eine Lösung, um die Captions komplett abzudrehen – doch die erfordert einen Eingriff in die functions.php, ist also nicht […]
@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?
Thanks for the solution! I’m trying it now.
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
[…] (via KatzWebDesign) […]
@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;
}
@Mikey, sorry it didn’t work for you. CSS doesn’t prevent extra markup, which is too bad, but if it works for you, that’s what counts!
The function doesn’t anymore work on WP 2.6.1
Parse error: syntax error, unexpected ‘}’ …
Could you please update it
@c.urdaneta – Make sure that you have a semicolon after
return $content
.Please include the complete error message so I can see what’s going on.
@zack – yes it is…
check here the funtion and the WP error maybe you can help me
@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’ );
@King Rat – Nice. I’ll need to try that out and I’ll add it to the main post.
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.
@Otto – thanks for the update!
[…] still using WordPress 2.6 and want to turn off captioning, I would suggest reading this or this, though I haven’t tried these methods […]
@Otto
Where we must put the code?
add_filter(’disable_captions’, create_function(’$a’,’return true;’));
Best Regards
Jauhari
@Jauhari – I believe you put it in your theme’s
function.php
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).
[…] Save it. (Code adopted from Katz Web Design) […]
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!
forgot to say I’m using 2.6.5 instead of 2.6.2
@dreedenator – just add a line like this:
$newExcerpt = preg_replace( '|[(.+?)](.+?[/\1])?|s', '', $newExcerpt );
That should do it!
[…] Then upload to your theme directory. And if you’re wondering which is yours, then go to Appearance on your WordPress admin panel and see what your current theme is. You should find a directory like that in your wp-content/themes directory on your server. That code I originally found here. […]
Going with mikey here. None of these scripts worked for me in 2.6. CSS – that old chestnut :]
.wp-caption-text {
display: none;
}