0

As I have a blog with several authors I would like to take all the design choises and set them as default. Unfortunately WordPress per default sets the class size-medium which I don't need. Furthermore WordPress includes the full domain path to the source instead of just giving src="/wp-content/....".

How could I change both presets?

1

Resolved

To remove the Class I added this snipped to my function.php

function remove_image_class( $classes ) {
  $unneededClasses = array( 'size-medium' );

  foreach ($unneededClasses as $unneededClass) {
    $classes = str_replace($unneededClass . ' ', '', $classes);
  }

  return $classes;
}

add_filter( 'get_image_tag_class', 'remove_image_class' );

As you see, I did define an array which contains all the unneeded classes (only one in my case) so it's easier to add more classes if needed.

To mate the paths relative I added this snippet to the functions.phpof my theme:

function relative_path_for_images($html, $id, $caption, $title, $align, $url, $size, $alt) {
  $imageurl = wp_get_attachment_image_src($id, $size);
  $relativeurl = wp_make_link_relative($imageurl[0]);
  $html = str_replace($imageurl[0],$relativeurl,$html);

  return $html;
}

add_filter('image_send_to_editor', 'relative_path_for_images', 10, 8);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.