
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!
Katz Web Design, is a 





38 responses so far ↓
Otto // July 21, 2008 at 9:05 am |
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.
Zack Katz // July 21, 2008 at 9:14 am |
@Otto — Thanks, I knew someone would have the “futureproof” way to do this.
Otto // July 21, 2008 at 9:49 am |
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.
LaFlamme // July 21, 2008 at 5:07 pm |
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.
Zack Katz // July 21, 2008 at 5:12 pm |
@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.
Otto // July 22, 2008 at 7:57 am |
Whoops. Add a ; after the return $content bit.
Otto // July 22, 2008 at 12:09 pm |
LaFlamme’s issue turned out to be the Max Banner Ads plugin. That breaks captions for some reason.
King Rat // July 22, 2008 at 9:14 pm |
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.
WordPress 2.6: Revisions-Feature deaktivieren auf datenschmutz.net // July 23, 2008 at 8:30 pm |
[...] 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 [...]
Zack Katz // July 24, 2008 at 7:00 am |
@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?
Matt A. // July 28, 2008 at 7:52 am |
Thanks for the solution! I’m trying it now.
Ash Haque // July 30, 2008 at 1:27 am |
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
Image-Caption in WordPress 2.6 entfernen | Phase 5 // July 31, 2008 at 8:17 am |
[...] (via KatzWebDesign) [...]
Zack Katz // July 31, 2008 at 8:42 am |
@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.
mikey // August 1, 2008 at 3:56 pm |
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;
}
Zack Katz // August 1, 2008 at 4:30 pm |
@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!
c.urdaneta // August 16, 2008 at 7:51 pm |
The function doesn’t anymore work on WP 2.6.1
Parse error: syntax error, unexpected ‘}’ …
Could you please update it
Zack Katz // August 18, 2008 at 10:43 am |
@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.
c.urdaneta // August 19, 2008 at 10:19 pm |
@zack – yes it is…
check here the funtion and the WP error maybe you can help me
Zack Katz // August 20, 2008 at 9:39 am |
@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!
King Rat // September 3, 2008 at 8:28 pm |
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’ );
Zack Katz // September 15, 2008 at 9:22 am |
@King Rat – Nice. I’ll need to try that out and I’ll add it to the main post.
Otto // September 17, 2008 at 1:18 pm |
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.
Zack Katz // September 18, 2008 at 9:40 am |
@Otto – thanks for the update!
Introducing CaptionKiller, because WordPress captions are bad | Game Pet // September 18, 2008 at 10:41 pm |
[...] 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 [...]
Jauhari // September 19, 2008 at 5:37 pm |
@Otto
Where we must put the code?
add_filter(’disable_captions’, create_function(’$a’,’return true;’));
Best Regards
Jauhari
Zack Katz // September 20, 2008 at 2:32 pm |
@Jauhari – I believe you put it in your theme’s
function.phpbimz // October 28, 2008 at 1:47 am |
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.
Zack Katz // October 30, 2008 at 8:31 am |
@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).
Simple Wordpress Tricks That You Thought You Know - Make Tech Easier // November 10, 2008 at 1:25 am |
[...] Save it. (Code adopted from Katz Web Design) [...]
Chris // December 5, 2008 at 5:04 pm |
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!
Lito // April 8, 2009 at 7:31 am |
Did you find a solution for this? I am having the same problem, besides, in Firefox when the tool tip goes away,, the menu also goes away. Let me know if you solved. Thanks.
Zack Katz // April 8, 2009 at 2:04 pm
Here’s what one guy did to remove the
titleattribute from the links (which is what is causing the tool tips). Personally, I would copy the wp_list_pages function into a theme’s functions.php file and modify the code a bit.dreedenator // December 7, 2008 at 2:42 am |
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!
dreedenator // December 7, 2008 at 2:44 am |
forgot to say I’m using 2.6.5 instead of 2.6.2
Zack Katz // December 11, 2008 at 9:29 am |
@dreedenator – just add a line like this:
$newExcerpt = preg_replace( '|\[(.+?)\](.+?\[/\\1\])?|s', '', $newExcerpt );That should do it!
How to Selectively Add Captions to Images in Wordpress 2.7 » Needcoffee.com // January 20, 2009 at 1:02 am |
[...] 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. [...]
Lewis Litanzios // January 24, 2009 at 10:30 pm |
Going with mikey here. None of these scripts worked for me in 2.6. CSS – that old chestnut :]
.wp-caption-text {
display: none;
}