Remove P tags from images

1) Filter wpautop() with ACF: function filter_ptags_on_images($content) { $content = preg_replace(‘/<p>\s*(<a .*>)?\s*(<img .* \/>)\s*(<\/a>)?\s*<\/p>/iU’, ‘\1\2\3’, $content); return preg_replace(‘/<p>\s*(<iframe .*>*.<\/iframe>)\s*<\/p>/iU’, ‘\1’, $content); } add_filter(‘acf_the_content’, ‘filter_ptags_on_images’); add_filter(‘the_content’, ‘filter_ptags_on_images’); If you have both of those try checking with a later priority on the add_filter. It’s possible the theme or plugin or acf is overriding you…. add_filter(‘acf_the_content’, ‘filter_ptags_on_images’, 9999); … Read more

How to upload image with simple form?

There are several parts. You need to add an enctype to the profile form. function edit_form_type_wpse_98375() { echo ‘ enctype=”multipart/form-data”‘; } add_action(‘user_edit_form_tag’,’edit_form_type_wpse_98375′); Then add a field to the form. function user_fields_wpse_98375($profileuser) { $_profile_photo = get_user_meta($profileuser->data->ID,’_profile_photo’,true); echo ‘<h3>’.__(‘Additional User Data’,THEME_TEXTDOMAIN).'</h3>’; echo ‘<tr class=”show-admin-bar”>’; echo ‘<th scope=”row”>’.__(‘Profile Photo’, THEME_TEXTDOMAIN).'</th>’; echo ‘<td’.$tspan.’>’; echo ‘<fieldset>’; echo ‘<legend class=”screen-reader-text”><span>’.__(‘Profile Photo’, … Read more

Img Src File path issue

No your file path setup is correct, you need to provide the absolute path in you img src for images to load on other pages as relative path would change to, http://yourwebsite.com/page/wp-content/themes/blankslate/images/morebutton.png and instead it should be http://yourwebsite.com/wp-content/themes/blankslate/images/morebutton.png So you should define a constant in your function.php for path to image directory, and then use … Read more

Image Scaling using get_the_post_thumbnail issue in WordPress

ALWAYS REGENERATE SOURCE SET ON IMAGE EDIT (New material, especially the custom function, follows conversation in comment thread.) The following function automatically regenerates a full source set after an image edit action. /** * ALWAYS REGENERATE FULL SOURCE SET AFTER EDITING IMAGE * answering StackExchange WordPress Development Question * see: https://wordpress.stackexchange.com/questions/288581/image-scaling-using-get-the-post-thumbnail-issue-in-wordpress/ * exploits code already … Read more

How do I detach images from posts?

If you view the Media Library in the list mode: /wp-admin/upload.php?mode=list then you will see the Attach/Detach links for each attachment. Each attachment can only be attached to a single parent through the post_parent field in the wp_posst table. Deleting an image from the post editor will not change the post_parent field to 0. Making … Read more

Replace image attributes for lazyload plugin (data-src)

instead of replacing the alt tag you could add-an-attribute-to-a-tag function add_lazyload($content) { $dom = new DOMDocument(); @$dom->loadHTML($content); foreach ($dom->getElementsByTagName(‘img’) as $node) { $oldsrc = $node->getAttribute(‘src’); $node->setAttribute(“data-original”, $oldsrc ); $newsrc=””.get_template_directory_uri().’/library/images/nothing.gif’; $node->setAttribute(“src”, $newsrc); } $newHtml = $dom->saveHtml(); return $newHtml; } note: i didn’t quite tested this code, so be careful 🙂

Applying automatic link class to images embedded to posts

You can run a filter on image_send_to_editor, the filter runs inside the get_image_send_to_editor function which is resposible for sending the link HTML that surrounds images sent to the editor. The filter can be found in core, in wp-admin/includes/media and is linked below for quick reference. core.trac.wordpress.org/browser/tags/3.1/wp-admin/includes/media.php

How to add image uploader to a custom widget?

Firstly, it is not recommended to use WP_PLUGIN_URL constant, instead use plugins_url() function. Second thing, it will not work when you put your files in the theme. You must put the necessary folder and file in the plugin if have to use this constant or function. Make sure, you have put correct path and you … Read more

Pb with responsive image sizes in WP 4.4

I handle the context like this: function wpse_216001_srcset() { // generate your Srcset here and return } function wpse_216001_sizes() { // generate your sizes attribute here and return } add_filter( ‘wp_calculate_image_sizes’, ‘wpse_216001_sizes’, 10 , 2 ); add_filter( ‘wp_calculate_image_srcset’, ‘wpse_216001_srcset’, 10 , 5); // call one of the standard WP image output functions here remove_filter( ‘wp_calculate_image_sizes’, … Read more