Seo Optimized Images - Version 1.1

Version Description

  1. Added title tag support
  2. Removed background.
  3. Setting for controling title tag.
Download this release

Release Info

Developer priyanshu.mittal
Plugin Icon 128x128 Seo Optimized Images
Version 1.1
Comparing to
See all releases

Code changes from version 1.0 to 1.1

css/plugin-admin-panel.css CHANGED
@@ -3701,7 +3701,7 @@ a.ui-datepicker-next {
3701
  }
3702
  }
3703
  .table_custom {
3704
- background: #eeeeee;
3705
  }
3706
  .table_custom tr th{
3707
  padding-left: 10px !important;
3701
  }
3702
  }
3703
  .table_custom {
3704
+ /* background: #eeeeee; */
3705
  }
3706
  .table_custom tr th{
3707
  padding-left: 10px !important;
readme.txt CHANGED
@@ -1,20 +1,20 @@
1
  === Seo Optimized Images ===
2
  Contributors: priyanshu.mittal
3
  Donate link: http://www.webriti.com/
4
- Tags: seo, images, seo for images, alt , alt tag, alt attribute, traffic
5
  Requires at least: 3.3+
6
- Tested up to: 4.4
7
- Stable tag: 1.0
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
11
- Seo Optmized Images Plugin lets you dynamically insert Seo Friendly alt attributes to your Images
12
 
13
  == Description ==
14
 
15
- The **SEO Optimized Images** plugin Seo Optmized Images Plugin lets you dynamically insert Seo Friendly alt attributes to your Images . Simply activate the plugin, provide the pattern and you are ready to go.
16
 
17
- The plugin dunamically replaces the alt tags and does not make changes to the database. So if you deactivate the plugin, everything will be back to as it was.
18
 
19
  Give **SEO Optmized Images** a try. We are sure you will like it.
20
 
@@ -32,7 +32,10 @@ In case you face any problem, contact us via the [Forums](https://wordpress.org/
32
 
33
 
34
  == Frequently Asked Questions ==
35
-
 
 
 
36
 
37
 
38
 
@@ -42,7 +45,10 @@ In case you face any problem, contact us via the [Forums](https://wordpress.org/
42
 
43
  == Changelog ==
44
 
45
-
 
 
 
46
  = 1.0 =
47
  1. Initial Plugin Release
48
 
1
  === Seo Optimized Images ===
2
  Contributors: priyanshu.mittal
3
  Donate link: http://www.webriti.com/
4
+ Tags: seo, images, seo for images, alt , alt tag, alt attribute, traffic, title tag, traffic, title attribute, seo optimization, optimization, image optimization, cool seo,search engine optimized images, search engine optimization, seo friendly images,seo friendly images plugin, google search optimized images,search friendly
5
  Requires at least: 3.3+
6
+ Tested up to: 4.3
7
+ Stable tag: 1.1
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
11
+ Seo Optmized Images Plugin lets you dynamically insert Seo Friendly alt and title attributes to your Images
12
 
13
  == Description ==
14
 
15
+ The **SEO Optimized Images** plugin Seo Optmized Images Plugin lets you dynamically insert Seo Friendly alt attributes and title attributes to your Images . Simply activate the plugin, provide the pattern and you are ready to go.
16
 
17
+ The plugin dynamically replaces the alt tags, title tags and does not make changes to the database. So if you deactivate the plugin, everything will be back to as it was.
18
 
19
  Give **SEO Optmized Images** a try. We are sure you will like it.
20
 
32
 
33
 
34
  == Frequently Asked Questions ==
35
+ 1. Did this plugin replace all the images alt and title tags in database?
36
+
37
+ The answer is big Noooooo. That's the beauty of this plugin without saving into database both the title and alt tags will respond depending on your settings.
38
+ If you want to restore your images seo tags than you just need to deactivate the plugin that's it.
39
 
40
 
41
 
45
 
46
  == Changelog ==
47
 
48
+ = 1.1 =
49
+ 1. Added title tag support
50
+ 2. Removed background.
51
+ 3. Setting for controling title tag.
52
  = 1.0 =
53
  1. Initial Plugin Release
54
 
seo-optimized-images-settings.php CHANGED
@@ -8,7 +8,8 @@ $default_options_data = array (
8
 
9
  'soi_alt_value' => '%name %title',
10
  'soi_title_value' => '',
11
- 'soi_override_value' => '1',
 
12
 
13
  );
14
 
@@ -26,8 +27,8 @@ if(isset($_POST['submit_general_settings_tab'])){
26
 
27
  $soi_options_array['soi_alt_value'] = esc_attr($_POST['soi_alt_value']);
28
  $soi_options_array['soi_title_value'] = esc_attr($_POST['soi_title_value']);
29
- $soi_options_array['soi_override_value'] = esc_attr($_POST['soi_override_value']);
30
-
31
  update_option ('soi_options_values', $soi_options_array );
32
 
33
  }
@@ -91,6 +92,9 @@ if(isset($_POST['submit_general_settings_tab'])){
91
  </div>
92
 
93
  <table class="form-table table_custom">
 
 
 
94
  <tr valign="top">
95
  <th scope="row"><?php _e('Alt Attribute Value','seoimages');?></th>
96
  <td><input type="text" name="soi_alt_value" value="<?php echo esc_attr( $soi_options_array['soi_alt_value'] ); ?>" />
@@ -98,8 +102,25 @@ if(isset($_POST['submit_general_settings_tab'])){
98
  <p class=""> %name - It will insert Image Name,<br> %title- It will insert Post Title.</p>
99
 
100
  </td>
101
- </tr>
102
- <!--
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
103
  <tr valign="top">
104
  <th scope="row"><?php _e('Title Attribute Value','seoimages');?></th>
105
  <td><input type="text" name="soi_title_value" value="<?php echo esc_attr( $soi_options_array['soi_title_value'] ); ?>" />
@@ -107,30 +128,22 @@ if(isset($_POST['submit_general_settings_tab'])){
107
 
108
  </td>
109
  </tr>
110
- -->
111
-
112
-
113
-
114
-
115
- <tr valign="top">
116
- <th scope="row"><?php _e('Override Existing Alt Tag','seoimages');?></th>
117
- <td><select id="soi_override_value" name="soi_override_value">
118
  <?php $override_setting = array(
119
  '1'=>'YES',
120
  '0'=>'NO'); ?>
121
  <?php foreach($override_setting as $key => $value) { ?>
122
- <option value="<?php echo $key; ?>" <?php if ($soi_options_array['soi_override_value']==$key) { echo 'selected="selected"'; } ?> >
123
  <?php _e($value,'seoimages') ?> </option>
124
  <?php } ?>
125
  </select>
126
- <p class=""><?php _e('Do you want to Over Ride existing alt tags?','seoimages') ?></p>
127
  </td>
128
  </tr>
129
 
130
-
131
-
132
-
133
-
134
 
135
  </table>
136
 
8
 
9
  'soi_alt_value' => '%name %title',
10
  'soi_title_value' => '',
11
+ 'soi_override_alt_value' => '1',
12
+ 'soi_override_title_value' => '1',
13
 
14
  );
15
 
27
 
28
  $soi_options_array['soi_alt_value'] = esc_attr($_POST['soi_alt_value']);
29
  $soi_options_array['soi_title_value'] = esc_attr($_POST['soi_title_value']);
30
+ $soi_options_array['soi_override_alt_value'] = esc_attr($_POST['soi_override_alt_value']);
31
+ $soi_options_array['soi_override_title_value'] = esc_attr($_POST['soi_override_title_value']);
32
  update_option ('soi_options_values', $soi_options_array );
33
 
34
  }
92
  </div>
93
 
94
  <table class="form-table table_custom">
95
+
96
+
97
+
98
  <tr valign="top">
99
  <th scope="row"><?php _e('Alt Attribute Value','seoimages');?></th>
100
  <td><input type="text" name="soi_alt_value" value="<?php echo esc_attr( $soi_options_array['soi_alt_value'] ); ?>" />
102
  <p class=""> %name - It will insert Image Name,<br> %title- It will insert Post Title.</p>
103
 
104
  </td>
105
+ </tr>
106
+
107
+ <tr valign="top">
108
+ <th scope="row"><?php _e('Override Existing Alt Tag','seoimages');?></th>
109
+ <td><select id="soi_override_alt_value" name="soi_override_alt_value">
110
+ <?php $override_setting = array(
111
+ '1'=>'YES',
112
+ '0'=>'NO'); ?>
113
+ <?php foreach($override_setting as $key => $value) { ?>
114
+ <option value="<?php echo $key; ?>" <?php if ($soi_options_array['soi_override_alt_value']==$key) { echo 'selected="selected"'; } ?> >
115
+ <?php _e($value,'seoimages') ?> </option>
116
+ <?php } ?>
117
+ </select>
118
+ <p class=""><?php _e('Do you want to Over Ride existing alt tags?','seoimages') ?></p>
119
+ </td>
120
+ </tr>
121
+
122
+
123
+
124
  <tr valign="top">
125
  <th scope="row"><?php _e('Title Attribute Value','seoimages');?></th>
126
  <td><input type="text" name="soi_title_value" value="<?php echo esc_attr( $soi_options_array['soi_title_value'] ); ?>" />
128
 
129
  </td>
130
  </tr>
131
+
132
+ <tr valign="top">
133
+ <th scope="row"><?php _e('Override Existing Title Tag','seoimages');?></th>
134
+ <td><select id="soi_override_title_value" name="soi_override_title_value">
 
 
 
 
135
  <?php $override_setting = array(
136
  '1'=>'YES',
137
  '0'=>'NO'); ?>
138
  <?php foreach($override_setting as $key => $value) { ?>
139
+ <option value="<?php echo $key; ?>" <?php if ($soi_options_array['soi_override_title_value']==$key) { echo 'selected="selected"'; } ?> >
140
  <?php _e($value,'seoimages') ?> </option>
141
  <?php } ?>
142
  </select>
143
+ <p class=""><?php _e('Do you want to Over Ride existing title tags?','seoimages') ?></p>
144
  </td>
145
  </tr>
146
 
 
 
 
 
147
 
148
  </table>
149
 
seo-optimized-images.php CHANGED
@@ -3,18 +3,18 @@
3
  /*
4
  Plugin Name: SEO Optimized Images
5
  Plugin URI: http://webriti.com
6
- Description:
7
- Version: 1.0
8
  Author: priyanshu.mittal
9
  Author URI: http://webriti.com
10
 
11
 
12
  */
13
- add_filter('the_content', 'soi_replace_alt', 100);
14
-
15
 
16
 
17
- function soi_replace_alt ($content, $alt_text='')
18
  {
19
 
20
 
@@ -23,6 +23,9 @@ function soi_replace_alt ($content, $alt_text='')
23
  $soi_options_array = get_option('soi_options_values');
24
 
25
  $alt_text = $soi_options_array['soi_alt_value'];
 
 
 
26
  $post_title = $post->post_title;
27
 
28
  // preapre the alt text
@@ -31,8 +34,11 @@ function soi_replace_alt ($content, $alt_text='')
31
  // Check if we need to overide the default alt and existing alt text
32
  // We will set the flag 1 or 0
33
 
 
 
34
 
35
- $flag = $soi_options_array['soi_override_value'];
 
36
 
37
  // Set the alt pattern
38
 
@@ -48,7 +54,7 @@ function soi_replace_alt ($content, $alt_text='')
48
 
49
  $soi_options_array = get_option('soi_options_values');
50
 
51
-
52
  $count = preg_match_all('/<img[^>]+>/i', $content, $images);
53
 
54
 
@@ -60,77 +66,119 @@ function soi_replace_alt ($content, $alt_text='')
60
  if($count>0)
61
  {
62
 
63
- // Here we will set the alt value to be inserted.
64
- // $t = "$post_title";
65
-
66
- // we want to output like alt = "text"
67
- // $t = 'alt = "'.$post_title.'"';
68
  $t = 'alt = "'.$alt_text.'"';
69
 
 
 
70
 
71
 
72
  foreach($images[0] as $img)
73
  { // check if the alt tag exists in the image
74
 
75
 
76
- // Get the Name of Image File.
77
 
78
  $output = preg_match_all( '/<img[^>]+src=[\'"]([^\'"]+)[\'"].*>/i', $img, $matches);
79
 
80
  $get_file_name = pathinfo($matches[1][0]);
81
  $image_file_name = $get_file_name['filename'];
82
 
83
- // Replace the Values
84
 
85
  $alt_text = str_replace('%title',$post_title,$alt_text );
86
  $alt_text = str_replace('%name',$image_file_name,$alt_text );
87
 
88
- $t = 'alt = "'.$alt_text.'"';
 
 
89
 
90
- $is_alt = preg_match_all('/ alt="([^"]*)"/i', $img, $alt);
 
 
 
 
 
 
 
91
 
92
-
93
  // In case there is not alt tag, create the tag and insert the value
94
-
95
- if($is_alt==0)
96
- { $new_img = str_replace('<img ', '<img '.$t , $img);
97
- $content = str_replace($img, $new_img, $content);
98
- }
99
-
100
-
101
- elseif($is_alt==1)
102
-
103
- {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
104
 
105
- $text = trim($alt[1][0]);
106
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
107
 
108
- // Check if the alt text is empty.
 
 
 
 
 
109
 
110
- if(empty($text))
111
- {
112
-
113
-
114
- $new_img = str_replace($alt[0][0], $t, $img);
115
-
116
- $content = str_replace($img, $new_img, $content);
117
- }
118
-
119
- // Should we override the existing alt tag
120
- if ($flag == "1")
121
-
122
- {
123
-
124
- $new_img = str_replace($alt[0][0], $t, $img);
125
-
126
- $content = str_replace($img, $new_img, $content);
127
-
128
-
129
- }
130
-
131
-
132
-
133
- }
134
  }
135
  }
136
 
3
  /*
4
  Plugin Name: SEO Optimized Images
5
  Plugin URI: http://webriti.com
6
+ Description: The **SEO Optimized Images** plugin Seo Optmized Images Plugin lets you dynamically insert Seo Friendly alt attributes and title attributes to your Images . Simply activate the plugin, provide the pattern and you are ready to go.
7
+ Version: 1.1
8
  Author: priyanshu.mittal
9
  Author URI: http://webriti.com
10
 
11
 
12
  */
13
+ add_filter('the_content', 'soi_replace_tags', 100);
14
+ // add_filter();
15
 
16
 
17
+ function soi_replace_tags ($content, $alt_text='',$title='')
18
  {
19
 
20
 
23
  $soi_options_array = get_option('soi_options_values');
24
 
25
  $alt_text = $soi_options_array['soi_alt_value'];
26
+ $title_text = $soi_options_array['soi_title_value'];
27
+
28
+ // get the post title for later use
29
  $post_title = $post->post_title;
30
 
31
  // preapre the alt text
34
  // Check if we need to overide the default alt and existing alt text
35
  // We will set the flag 1 or 0
36
 
37
+ //check setting for overinding alt tag
38
+ $alt_flag = $soi_options_array['soi_override_alt_value'];
39
 
40
+ //check setting for overinding title tag
41
+ $title_flag = $soi_options_array['soi_override_title_value'];
42
 
43
  // Set the alt pattern
44
 
54
 
55
  $soi_options_array = get_option('soi_options_values');
56
 
57
+ // count number of images found in content
58
  $count = preg_match_all('/<img[^>]+>/i', $content, $images);
59
 
60
 
66
  if($count>0)
67
  {
68
 
69
+ // Here we will set the alt value to be inserted.
70
+ // $t = "$post_title"
71
+ // we want to output like alt = "text"
72
+
 
73
  $t = 'alt = "'.$alt_text.'"';
74
 
75
+ // we want to output like title = "text"
76
+ $t_title = 'title = "'.$title_text.'"';
77
 
78
 
79
  foreach($images[0] as $img)
80
  { // check if the alt tag exists in the image
81
 
82
 
83
+ // Get the Name of Image Files.
84
 
85
  $output = preg_match_all( '/<img[^>]+src=[\'"]([^\'"]+)[\'"].*>/i', $img, $matches);
86
 
87
  $get_file_name = pathinfo($matches[1][0]);
88
  $image_file_name = $get_file_name['filename'];
89
 
90
+ // Replace the Values for alt tag
91
 
92
  $alt_text = str_replace('%title',$post_title,$alt_text );
93
  $alt_text = str_replace('%name',$image_file_name,$alt_text );
94
 
95
+ // replace the values for title tag.
96
+ $title_text = str_replace('%title',$post_title,$title_text );
97
+ $title_text = str_replace('%name',$image_file_name,$title_text );
98
 
99
+ //configure tags with specified values from option panel.
100
+ $t = 'alt = "'.$alt_text.'"';
101
+ $t_title = 'title = "'.$title_text.'"';
102
+
103
+ //take the alt tag out from the image html markup
104
+ $is_alt = preg_match_all('/ alt="([^"]*)"/i', $img, $alt);
105
+
106
+
107
 
108
+ ////////////////// check for alt tag /////////////////////////
109
  // In case there is not alt tag, create the tag and insert the value
110
+ if ($alt_flag == "1")
111
+
112
+ {
113
+ // if alt tag is not present than insert the tag.
114
+ if($is_alt == 0)
115
+ { $new_img = str_replace('<img ', '<img '.$t , $img);
116
+ $content = str_replace($img, $new_img, $content);
117
+ }
118
+
119
+ // if alt tag is present
120
+ elseif($is_alt==1)
121
+
122
+ {
123
+
124
+ $text = trim($alt[1][0]);
125
+
126
+
127
+ // Check if the alt text is empty.
128
+
129
+ if(empty($text))
130
+ {
131
+
132
+
133
+ $new_img = str_replace($alt[0][0], $t, $img);
134
+
135
+ $content = str_replace($img, $new_img, $content);
136
+ }
137
+
138
+
139
+
140
+
141
+ // Should we override the existing alt tag
142
+ if ($alt_flag == "1")
143
+
144
+ {
145
+
146
+ $new_img = str_replace($alt[0][0], $t, $img);
147
+
148
+ $content = str_replace($img, $new_img, $content);
149
+
150
+
151
+ }
152
+
153
+ }
154
+ }//////////////////// checked for alt tag ////////////////////
155
 
156
+ ///////////////// check for title tag ///////////////////////////
157
 
158
+
159
+ // first check weither title tag needs to be overide
160
+ if($title_flag == "1"){
161
+
162
+ if(!isset($new_img)) $new_img=$img; // when alt tag is not overridden, than , use actual image markup ie $new_img.
163
+
164
+ $is_title = preg_match_all('/ title="([^"]*)"/i', $new_img, $title);
165
+
166
+ // check if title tag is not present in the img tag
167
+ if($is_title == 0)
168
+ {
169
+ // create the title tag and insert the tag
170
+ $final_img = str_replace('<img ', '<img '.$t_title , $new_img);
171
+ $content = str_replace($new_img, $final_img, $content);
172
+
173
+ } else {
174
 
175
+ // you are here bcs title tags exsis and needs to be override
176
+ $final_img = str_replace($title[0][0], $t_title, $new_img);
177
+ $content = str_replace($new_img, $final_img, $content);
178
+ }
179
+ }
180
+ ///////////////////// title tag checked ////////////////
181
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
182
  }
183
  }
184