[gnome-web-www] Make post images to use img-responsive CSS class
- From: Tom Tryfonidis <tomtryf src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-web-www] Make post images to use img-responsive CSS class
- Date: Thu, 2 Feb 2017 18:06:09 +0000 (UTC)
commit 7e25fc2ee54fa618a033f26e22237fe869943592
Author: Tom Tryfonidis <tomtryf gnome org>
Date: Thu Feb 2 20:05:01 2017 +0200
Make post images to use img-responsive CSS class
theme/functions.php | 19 +++++++++++++++++++
1 files changed, 19 insertions(+), 0 deletions(-)
---
diff --git a/theme/functions.php b/theme/functions.php
index a178576..23e1b3f 100644
--- a/theme/functions.php
+++ b/theme/functions.php
@@ -519,6 +519,25 @@ function custom_mimes_types ($existing_mimes) {
require_once('lib/wp-bootstrap-navwalker.php');
/*
+ * Add img-responsive CSS class to all post images
+ */
+
+function bootstrap_responsive_images( $html ){
+ $classes = 'img-responsive'; // separated by spaces, e.g. 'img image-link'
+ // check if there are already classes assigned to the anchor
+ if ( preg_match('/<img.*? class="/', $html) ) {
+ $html = preg_replace('/(<img.*? class=".*?)(".*?\/>)/', '$1 ' . $classes . ' $2', $html);
+ } else {
+ $html = preg_replace('/(<img.*?)(\/>)/', '$1 class="' . $classes . '" $2', $html);
+ }
+ // remove dimensions from images, does not need it!
+ // Keep dimensions for now..
+ // $html = preg_replace( '/(width|height)=\"\d*\"\s/', "", $html );
+ return $html;
+}
+add_filter( 'the_content','bootstrap_responsive_images',10 );
+
+/*
* GNOME Grass Customizer
*/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]