WordPress.org

Ready to get started?Download WordPress

Forums

Where To Find Code For Image Posts? (18 posts)

  1. Andrew
    Member
    Posted 2 years ago #

    Hello.

    Can anyone tell me where to find the code for displaying images in posts?

    Please help,

    Andrew

  2. deepbevel
    Member
    Posted 2 years ago #

    <a href="http://www.(link goes here)"><img class="aligncenter size-medium" title="" src="http://www.path to your image" alt="" width="" height="" /></a>
    However, the code gets written automatically in the post when you insert an image from the media library.

  3. Andrew
    Member
    Posted 2 years ago #

    Okay, but which is the .php file which originates the code? And can I change it?

    Please help.

    Thank you,

    Andrew

  4. deepbevel
    Member
    Posted 2 years ago #

    not sure where/how it gets generated, it's a function of the WP gallery, probably WP core files, and not in template files that I'm aware of. What is the goal?

  5. Andrew
    Member
    Posted 2 years ago #

    I found the function that generates the code for images in posts in media.php, but where in the theme is it called?

    Please help,

    Andrew

  6. deepbevel
    Member
    Posted 2 years ago #

    If I knew what the goal was I might be of some assistance, but it's quite likely beyond me, hopefully someone else will chime in..Good luck!

  7. Andrew
    Member
    Posted 2 years ago #

    I would like to alter the code for images. i.e. remove it from the div and remove the caption, etc... generally alter the code for images.

    In other words, completely control the display of images in posts.

    Please help.

    Thank you,

    Andrew

  8. Andrew
    Member
    Posted 2 years ago #

    The media.php file uses a shortcode to insert the image into a div:

    add_shortcode('wp_caption', 'img_caption_shortcode');
    add_shortcode('caption', 'img_caption_shortcode');

    And a filter to disable it:

    function img_caption_shortcode($attr, $content = null) {
    
    	// Allow plugins/themes to override the default caption template.
    	$output = apply_filters('img_caption_shortcode', '', $attr, $content);
    	if ( $output != '' )
    		return $output;
    
    	extract(shortcode_atts(array(
    		'id'	=> '',
    		'align'	=> 'alignnone',
    		'width'	=> '',
    		'caption' => ''
    	), $attr));
    
    	if ( 1 > (int) $width || empty($caption) )
    		return $content;
    
    	if ( $id ) $id = 'id="' . esc_attr($id) . '" ';
    
    	return '<div ' . $id . 'class="wp-caption ' . esc_attr($align) . '" style="width: ' . (10 + (int) $width) . 'px">'
    	. do_shortcode( $content ) . '<p class="wp-caption-text">' . $caption . '</p></div>';
    }

    How can I add a filter to disable the caption shortcode?

    Does anyone know exactly where these codes are called or implemented?

    Please help.

    Thank you,

    Andrew

  9. deepbevel
    Member
    Posted 2 years ago #

    yes, I think I know what you are trying to do, try this plugin:cleaner-wordpress-gallery-plugin

  10. Andrew
    Member
    Posted 2 years ago #

    I would like to avoid using any plugins for this.

    Thank you,

    Andrew

  11. deepbevel
    Member
    Posted 2 years ago #

    okay, .. well here's my best a shot at it anyway: remove-default-inline-style-of-wp-caption

  12. Andrew
    Member
    Posted 2 years ago #

    The code on the link says it can remove the div but it doesn't working for me. The div is still being inserted.

    Can I just use a filter to prevent the function that creates the div (img_caption_shortcode) from being called?

    Please help.

    Thank you,

    Andrew

  13. deepbevel
    Member
    Posted 2 years ago #

    here's another shot, ..if nothing else I'm keeping your request at the top of the forum, hopefully someone who knows will come along soon..

    imath...you out there? help!

    codex.wordpress.org/Function_Reference/add_filter

  14. Andrew
    Member
    Posted 2 years ago #

    Can anyone help me change the output of the img_caption_shortcode?

    I would like to alter the code, perhaps to remove the div from it.

    I've had no luck doing this, when I remove the div from the code, the div is no longer output but the caption isn't inserted anymore either.

    Here is the code I'm using now:

    [code moderated per forum rules - please use the http://pastebin.com/ for any code longer than 10 lines]

    Which returns just the image, no caption.

    Any way to have the caption return?

    Please help.

    Thank you,

    Andrew

  15. Iamhere
    Member
    Posted 2 years ago #

    Hi

    I am facing a similar issue. I want to disable the image caption from displaying on the_excerpt - it seems the only way to do this is use a conditional tag with a to filter to disable the caption: apply_filters('img_caption_shortcode')

    I've not managed to achieve this yet, so would be interested to hear about any solution you find.

  16. deepbevel
    Member
    Posted 2 years ago #

    If you are okay with a plugin, in your case advanced-excerpt would be perfect. It allows you to filter all exerpt output (including image caption) via global admin settings or template tag for individual instances ot the_excerpt.

  17. Iamhere
    Member
    Posted 2 years ago #

    Hi deepbevel, thanks for your response.
    I'm not a fan of plugins and prefer to code in functions file.

    In this instance, it was only for one specific category and I found a simple, but a bit dirty, work-around: add a body class to the specific page, then display: none in the css for that page !

    In case anyone else is reading this, here's the code I used

    body#projects p.wp-caption-text {
    display: none;
    }

    I'm surprised there is not a simple function to allow the filtering of captions!

  18. deepbevel
    Member
    Posted 2 years ago #

    actually, that looks pretty clean to me.

    Some excerpt control from the admin settings would be a nice core feature, some themes include it to some extent. But actually, isn't that kinda like using a plugin? (haha) .. I always prefer to code myself too if I can, then I know exactly what's going on and it's easier to tweak it later.

    I'm finding css to be a great solution more and more all the time, it's usually not to complicated, especially with a dev tool like Firebug. Nice solution!

Topic Closed

This topic has been closed to new replies.

About this Topic