WordPress.org

Support

Support » How-To and Troubleshooting » Where To Find Code For Image Posts?

Where To Find Code For Image Posts?

  • Andrew

    @ndrwglrzayahoocom

    Hello.

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

    Please help,

    Andrew

Viewing 15 replies - 1 through 15 (of 17 total)
  • <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.

    Andrew

    @ndrwglrzayahoocom

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

    Please help.

    Thank you,

    Andrew

    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?

    Andrew

    @ndrwglrzayahoocom

    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

    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!

    Andrew

    @ndrwglrzayahoocom

    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

    Andrew

    @ndrwglrzayahoocom

    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

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

    Andrew

    @ndrwglrzayahoocom

    I would like to avoid using any plugins for this.

    Thank you,

    Andrew

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

    Andrew

    @ndrwglrzayahoocom

    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

    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

    Andrew

    @ndrwglrzayahoocom

    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

    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.

    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.

Viewing 15 replies - 1 through 15 (of 17 total)
  • The topic ‘Where To Find Code For Image Posts?’ is closed to new replies.
Skip to toolbar