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!

Related posts:

  1. Remove shortcode from All in One SEO Pack in WordPress 2.6
  2. Get Adjacent Images – More WordPress Functions
  3. Incorporate WordPress with Interspire Shopping Cart
  4. Lottery Results – A New WordPress Plugin
  5. How to tell if your WordPress Plugin or Widget is Activated in WordPress

This entry was posted in Code and tagged , , , , , . Bookmark the permalink.
  • http://ottodestruct.com Otto

    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.

  • http://www.seodenver.com Zack Katz

    @Otto — Thanks, I knew someone would have the “futureproof” way to do this.

  • http://ottodestruct.com Otto

    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.

  • http://www.marklaflamme.com LaFlamme

    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.

  • http://www.seodenver.com Zack Katz

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

  • http://ottodestruct.com Otto

    Whoops. Add a ; after the return $content bit.

  • http://ottodestruct.com Otto

    LaFlamme’s issue turned out to be the Max Banner Ads plugin. That breaks captions for some reason.

  • http://reading.kingrat.biz/ King Rat

    Yeah, but that solution isn’t quite the same as what I’m interested in. I want to turn off the insertion of the 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.

  • Pingback: WordPress 2.6: Revisions-Feature deaktivieren auf datenschmutz.net

  • http://www.seodenver.com Zack Katz

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

    Thanks for the solution! I’m trying it now.

  • http://www.ashhaque.com/ Ash Haque

    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

  • Pingback: Image-Caption in WordPress 2.6 entfernen | Phase 5

  • http://www.seodenver.com Zack Katz

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

  • http://herebox.org mikey

    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;

  • http://www.seodenver.com Zack Katz

    @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!

  • http://blog.iws.com.ve/ c.urdaneta

    The function doesn’t anymore work on WP 2.6.1
    Parse error: syntax error, unexpected ‘}’ …
    Could you please update it

  • http://www.seodenver.com Zack Katz

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

  • http://blog.iws.com.ve/ c.urdaneta

    @zack – yes it is…

    check here the funtion and the WP error maybe you can help me

  • http://www.seodenver.com Zack Katz

    @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!

  • http://reading.kingrat.biz/ King Rat

    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’ );

  • http://www.seodenver.com Zack Katz

    @King Rat – Nice. I’ll need to try that out and I’ll add it to the main post.

  • http://ottodestruct.com Otto

    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.

  • http://www.seodenver.com Zack Katz

    @Otto – thanks for the update!

  • Pingback: Introducing CaptionKiller, because WordPress captions are bad | Game Pet

  • http://www.jauhari.net Jauhari

    @Otto
    Where we must put the code?

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

    Best Regards

    Jauhari

  • http://www.seodenver.com Zack Katz

    @Jauhari – I believe you put it in your theme’s function.php

  • bimz

    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.

  • http://www.seodenver.com Zack Katz

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

  • Pingback: Simple Wordpress Tricks That You Thought You Know - Make Tech Easier

  • Chris

    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!

  • dreedenator

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

    forgot to say I’m using 2.6.5 instead of 2.6.2

  • http://www.seodenver.com Zack Katz

    @dreedenator – just add a line like this:
    $newExcerpt = preg_replace( '|\[(.+?)\](.+?\[/\\1\])?|s', '', $newExcerpt );

    That should do it!

  • Pingback: How to Selectively Add Captions to Images in Wordpress 2.7 » Needcoffee.com

  • http://www.ldexterldesign.co.uk/ Lewis Litanzios

    Going with mikey here. None of these scripts worked for me in 2.6. CSS – that old chestnut :]

    .wp-caption-text
    display: none;

  • http://www.smart.dj Lito

    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.

  • http://www.seodenver.com Zack Katz

    Here’s what one guy did to remove the title attribute 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.