Changeset 1541826
- Timestamp:
- 11/28/2016 10:01:14 AM (9 years ago)
- Location:
- ect-seo/trunk
- Files:
-
- 2 edited
-
index.php (modified) (18 diffs)
-
readme.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
ect-seo/trunk/index.php
r1143046 r1541826 2 2 /* 3 3 Plugin Name:ECT SEO 4 Plugin URI: http://www.ecommercetemplates.com/ wordpress/wp-plugins.asp4 Plugin URI: http://www.ecommercetemplates.com//wp-plugins.asp 5 5 Description:This plugin will automatically add meta description tags and will set title the for all ECT store pages. 6 6 Author:Andy Chapman 7 7 Author URI:http://www.ecommercetemplates.com 8 Version:1. 38 Version:1.4 9 9 */ 10 function ect_seo_fun($arr) 10 11 add_filter('pre_get_document_title', 'filter_pagetitle',10,1); 12 add_action('wp_head', 'add_cs_meta',1); 13 add_shortcode('ect_seo','ect_seo_fun_short'); 14 15 function ect_seo_fun_short() 16 { 17 remove_action('wp_head','_wp_render_title_tag',1); 18 remove_action('wp_head','add_cs_meta',1); 19 $T=ect_seo_fun('t') ; 20 echo '<title>'.$T.'</title>'; 21 add_cs_meta(); 22 } 23 function filter_pagetitle($title) 24 { 25 $Ttl=ect_seo_fun('t'); 26 return $Ttl; 27 } 28 function add_cs_meta() 29 { 30 $Meta=ect_seo_fun('m'); 31 echo '<meta name="Description" content="'.$Meta.'" />'; 32 } 33 function GetCatInfoPDetail($PID) 34 { 35 global $db_username,$db_password,$db_name,$db_host,$ECTWPDB,$productid; 36 37 if(!empty($db_username) && !empty($PID)) 38 { 39 $SiteRoot=WP_CONTENT_DIR; 40 include_once $SiteRoot."/../vsadmin/includes.php"; 41 include_once $SiteRoot."/../vsadmin/db_conn_open.php"; 42 if(!$ECTWPDB) 43 { 44 $ECTWPDB=new wpdb($db_username, $db_password, $db_name, $db_host); 45 $PArr=$ECTWPDB->get_row("select pID,pName,pSection from products where pID='".$PID."'"); 46 $Cats=$ECTWPDB->get_row("select sectionName,topsection from sections where sectionID=".$PArr->pSection); $Cats1=$ECTWPDB->get_row("select sectionName from sections where sectionID=".$Cats->topsection); 47 48 $Data=array( 49 'PName'=>$PArr->pName, 50 'PId'=>$PArr->pID, 51 'SecName'=>$Cats->sectionName, 52 'CatName'=>$Cats1->sectionName 53 ); 54 return $Data; 55 } 56 } 57 } 58 function GetCatName($CatID,$Sec='') 59 { 60 global $db_username,$db_password,$db_name,$db_host,$ECTWPDB; 61 62 if(!empty($db_username) && !empty($CatID)) 63 { 64 $SiteRoot=WP_CONTENT_DIR; 65 include_once $SiteRoot."/../vsadmin/includes.php"; 66 include_once $SiteRoot."/../vsadmin/db_conn_open.php"; 67 if(!$ECTWPDB) 68 { 69 $ECTWPDB=new wpdb($db_username, $db_password, $db_name, $db_host); 70 } 71 //$Tbls=$ECTWPDB->get_results("show tables"); 72 if(empty($Sec)) 73 { 74 $Cats=$ECTWPDB->get_row("select sectionName from sections where sectionID=".$CatID); 75 if(!empty($Cats)) 76 return $Cats->sectionName; 77 } 78 else 79 { 80 $Cats=$ECTWPDB->get_row("select topSection from sections where sectionID=".$CatID); 81 if(!empty($Cats)) 82 { 83 $Cats1=$ECTWPDB->get_row("select sectionName,topSection from sections where sectionID=".$Cats->topSection); 84 if(!empty($Cats1)) return $Cats1->sectionName; 85 } 86 } 87 88 } 89 return $CatID; 90 } 91 function ect_seo_fun($m) 11 92 { 12 93 $Title=$Meta=$Key=''; 13 global $pagetitle,$topsection,$sectionname,$sectiondescription,$productname,$productid,$productdescription; 94 global $pagetitle,$topsection,$sectionname,$sectiondescription,$productname,$productid,$productdescription,$usecategoryname; 95 $DataArrTemp=array($pagetitle,$topsection,$sectionname,$sectiondescription,$productname,$productid,$productdescription); 96 97 $BlogInfo=esc_attr(get_bloginfo('name', 'display')) ; 98 if(is_front_page() || is_home()) 99 { 100 return GenerateSeoTags('front_page',$Title,$Meta,$Key,$m); 101 } 102 14 103 if(@$GLOBALS['ectcartpage']=='proddetail') 15 104 { 16 $Cat=isset($_GET['prod']) ? $_GET['prod'] : ''; 105 $Pod=isset($productid) ? $productid : $_GET['prod']; 106 $PTitleInfo=GetCatInfoPDetail($Pod); 107 17 108 $Title=esc_attr(get_bloginfo('name', 'display')).' store: '.$productname. " | " . $sectionname. " | " . $productid; 18 109 $Srh=array('%SHOW_BLOG_NAME%','%PROD_NAME%','%SEC_NAME%','%PROD_ID%','%CAT_NAME%'); 19 110 $BlogInfo=esc_attr(get_bloginfo('name', 'display')) ; 20 21 22 $Rep=array($BlogInfo,$productname,$sectionname,$productid,$Cat); 23 111 $productname=empty($productname) ? $PTitleInfo['PName'] : $productname; 112 $sectionname=empty($sectionname) ? $PTitleInfo['SecName'] : $sectionname; 113 114 $productid=empty($productid) ? $PTitleInfo['PId'] : $productid; 115 $topsection=empty($topsection) ? $PTitleInfo['CatName'] : $topsection; 116 117 $Rep=array($BlogInfo,$productname,$sectionname,$productid,$topsection); 24 118 $Frm=get_option('ect_seo_pdts',true); 25 119 $Title=str_replace($Srh,$Rep,$Frm); 26 120 $Meta=str_replace('"','"',$productdescription); 27 return GenerateSeoTags('proddetail',$Title,$Meta, '');121 return GenerateSeoTags('proddetail',$Title,$Meta,$Key,$m); 28 122 } 29 123 elseif(@$GLOBALS['ectcartpage']=='products' ) 30 124 { 31 $Cat=isset($_GET['cat']) ? $_GET['cat'] : ''; 125 $Cat=GetCatName($_GET['cat']); 126 $SecName=GetCatName($_GET['cat'],'sec'); 32 127 // $Title=esc_attr(get_bloginfo('name', 'display')).' store: '; 33 128 34 129 $Srh=array('%SHOW_BLOG_NAME%','%PROD_NAME%','%SEC_NAME%','%PROD_ID%','%CAT_NAME%'); 35 130 $BlogInfo=esc_attr(get_bloginfo('name', 'display')) ; 36 $Rep=array($BlogInfo,$productname,$sectionname,$productid,$Cat); 37 $Frm=get_option('ect_seo_pts',true); 38 $Title=str_replace($Srh,$Rep,$Frm); 39 131 132 $sectionname=empty($sectionname) ? $SecName : $sectionname; 133 $topsection=empty($topsection) ? $Cat : $topsection; 134 135 $Rep=array($BlogInfo,$productname,$sectionname,$productid,$topsection); 136 $Frm=get_option('ect_seo_pts',true); $Title=str_replace($Srh,$Rep,$Frm); 137 40 138 /*if($topsection!= "") 41 139 $Title=$Title.$topsection . ",3 "; … … 43 141 $Meta=str_replace('"','"',$sectiondescription); 44 142 45 46 return GenerateSeoTags('products',$Title,$Meta, '');143 144 return GenerateSeoTags('products',$Title,$Meta,$Key,$m); 47 145 } 48 146 elseif(@$GLOBALS['ectcartpage']=='categories') 49 147 { 50 $Cat=isset($_GET['cat']) ? $_GET['cat'] : ''; 51 $Title=esc_attr(get_bloginfo('name', 'display')).' store: '; 52 if($topsection!= "") 53 $Title=$Title.$topsection. ", "; 54 $Title=$Title.$sectionname; 148 $Cat=GetCatName($_GET['cat']); 149 $SecName=GetCatName($_GET['cat'],'sec'); 150 //$Title=esc_attr(get_bloginfo('name', 'display')).' store: '; 151 // if($topsection!= "") 152 // $Title=$Title.$topsection. ", "; 153 // $Title=$Title.$sectionname; 55 154 $Meta=str_replace('"','"',$sectiondescription); 56 155 57 156 $Srh=array('%SHOW_BLOG_NAME%','%PROD_NAME%','%SEC_NAME%','%PROD_ID%','%CAT_NAME%'); 58 157 $BlogInfo=esc_attr(get_bloginfo('name', 'display')) ; 59 $Rep=array($BlogInfo,$productname,$sectionname,$productid,$Cat); 60 $Frm=get_option('ect_seo_cts',true); 61 $Title=str_replace($Srh,$Rep,$Frm); 62 63 return GenerateSeoTags('categories',$Title,$Meta,''); 158 159 $topsection=!empty($topsection ) ? $topsection : $Cat; 160 161 $sectionname=$sectionname; 162 if(!$sectionname) 163 $sectionname=$SecName; 164 $Rep=array($BlogInfo,$productname,$sectionname,$productid,$topsection); 165 $Frm='%CAT_NAME% | %SHOW_BLOG_NAME% '; 166 $Title=str_replace($Srh,$Rep,$Frm); 167 if($topsection) 168 return GenerateSeoTags('categories',$Title,$Meta,$Key,$m,1); 169 else 170 return GenerateSeoTags('categories','','','',$m); 64 171 } 65 172 elseif(@$GLOBALS['ectcartpage']=='cart') … … 68 175 $Meta ='Online store shopping cart and checkout for '.esc_attr(get_bloginfo('name', 'display')); 69 176 $Key =''; 70 return GenerateSeoTags('cart',$Title,$Meta,$Key );177 return GenerateSeoTags('cart',$Title,$Meta,$Key,$m).' - '.$BlogInfo; 71 178 } 72 179 elseif(@$GLOBALS['ectcartpage']=='affiliate') … … 74 181 $Title='Affiliate program for '.esc_attr(get_bloginfo('name', 'display')); 75 182 $Meta=esc_attr(get_bloginfo('name', 'display')).' affiliate program'; 76 return GenerateSeoTags('affiliate',$Title,$Meta );183 return GenerateSeoTags('affiliate',$Title,$Meta,$Key,$m).' - '.$BlogInfo; 77 184 } 78 185 elseif(@$GLOBALS['ectcartpage']=='clientlogin') … … 80 187 $Title='Customer account for '.esc_attr(get_bloginfo('name', 'display')); 81 188 $Meta=esc_attr(get_bloginfo('name', 'display')).' client login'; 82 return GenerateSeoTags('clientlogin',$Title,$Meta );189 return GenerateSeoTags('clientlogin',$Title,$Meta,$Key,$m).' - '.$BlogInfo; 83 190 } 84 191 elseif(@$GLOBALS['ectcartpage']=='giftcertificate') … … 86 193 $Title='Purchase a gift certificate from '.esc_attr(get_bloginfo('name', 'display')); 87 194 $Meta=esc_attr(get_bloginfo('name', 'display')).' gift certificates'; 88 return GenerateSeoTags('giftcertificate',$Title,$Meta );195 return GenerateSeoTags('giftcertificate',$Title,$Meta,$Key,$m).' - '.$BlogInfo; 89 196 } 90 197 elseif(@$GLOBALS['ectcartpage']=='orderstatus') … … 92 199 $Title='Check the status of your order on '.esc_attr(get_bloginfo('name', 'display')); 93 200 $Meta=esc_attr(get_bloginfo('name', 'display')).' order status'; 94 return GenerateSeoTags('orderstatus',$Title,$Meta );201 return GenerateSeoTags('orderstatus',$Title,$Meta,$Key,$m).' - '.$BlogInfo; 95 202 } 96 203 elseif(@$GLOBALS['ectcartpage']=='search') … … 98 205 $Title='Search for products on '.esc_attr(get_bloginfo('name', 'display')); 99 206 $Meta=esc_attr(get_bloginfo('name', 'display')).' search'; 100 return GenerateSeoTags('search',$Title,$Meta );207 return GenerateSeoTags('search',$Title,$Meta,$Key,$m).' - '.$BlogInfo; 101 208 } 102 209 elseif(@$GLOBALS['ectcartpage']=='sorry') … … 104 211 $Title='Sorry - there seems to be a problem with the order'; 105 212 $Meta='Sorry - there seems to be a problem with the order'; 106 return GenerateSeoTags('sorry',$Title,$Meta );213 return GenerateSeoTags('sorry',$Title,$Meta,$Key,$m).' - '.$BlogInfo; 107 214 } 108 215 elseif(@$GLOBALS['ectcartpage']=='thanks') … … 110 217 $Title='Thank you for purchasing from '.esc_attr(get_bloginfo('name', 'display')); 111 218 $Meta=esc_attr(get_bloginfo('name', 'display')).' confirmation page'; 112 return GenerateSeoTags('thanks',$Title,$Meta );219 return GenerateSeoTags('thanks',$Title,$Meta,$Key,$m).' - '.$BlogInfo; 113 220 } 114 221 elseif(@$GLOBALS['ectcartpage']=='tracking') … … 116 223 $Title='Track your purchase from '.esc_attr(get_bloginfo('name', 'display')); 117 224 $Meta=esc_attr(get_bloginfo('name', 'display')).' tracking page'; 118 return GenerateSeoTags('tracking',$Title,$Meta); 119 } 120 elseif(is_front_page()){ 121 122 return GenerateSeoTags('front_page',$Title,$Meta,''); 225 return GenerateSeoTags('tracking',$Title,$Meta,$Key,$m).' - '.$BlogInfo; 123 226 } 124 227 else 125 { 126 127 if ( defined( 'WPSEO_VERSION' ) ) { 128 // WordPress SEO is activated 129 $Title=wp_title('',false); 130 return GenerateSeoTags('',$Title,''); 131 } else { 132 // WordPress SEO is not activated 133 $Title=wp_title( '|', false, 'right' ); 134 return GenerateSeoTags('',$Title,''); 135 } 136 } 137 } 138 add_shortcode('ect_seo','ect_seo_fun'); 228 return GenerateSeoTags('',$Title,$Meta,$Key,$m).' - '.$BlogInfo; 229 } 139 230 add_action('admin_menu','ect_seo_nav'); 140 231 function ect_seo_nav() … … 161 252 <li> 162 253 <label><?php echo ucfirst(str_replace('_',' ',$P));?></label> 163 <input type="text" name="seo_data_title[<?php echo $ p?>]" value="<?php echo stripslashes(get_option('ect_seo_'.$P.'_title'))?>" />164 <input type="text" name="seo_data_metacnt[<?php echo $ p?>]" value="<?php echo stripslashes(get_option('ect_seo_'.$P.'_meta_description'))?>" />254 <input type="text" name="seo_data_title[<?php echo $P?>]" value="<?php echo stripslashes(get_option('ect_seo_'.$P.'_title'))?>" /> 255 <input type="text" name="seo_data_metacnt[<?php echo $P?>]" value="<?php echo stripslashes(get_option('ect_seo_'.$P.'_meta_description'))?>" /> 165 256 </li> 166 257 167 258 <?php endif;?> 168 259 <?php endforeach;?> … … 173 264 <label>Product Detail Page </label> 174 265 <input type="text" name="pdts" value="<?php echo get_option('ect_seo_pdts',true)?>" style="width:666px"/><br /> 175 <code class="code">%SHOW_BLOG_NAME% store :%PROD_NAME% | %SEC_NAME% | %PROD_ID% | %CAT_NAME% </code>266 <code class="code">%SHOW_BLOG_NAME% store | %PROD_NAME% | %SEC_NAME% | %PROD_ID% | %CAT_NAME% </code> 176 267 </li> 177 268 <li> 178 269 <label>Product Page </label> 179 270 <input type="text" name="pts" value="<?php echo get_option('ect_seo_pts',true)?>" style="width:666px"/><br /> 180 <code class="code">%SHOW_BLOG_NAME% store : %PROD_NAME% | %SEC_NAME% | %PROD_ID% | %CAT_NAME% </code>271 <code class="code">%SHOW_BLOG_NAME% store |: %SEC_NAME% | %CAT_NAME% </code> 181 272 </li> 182 273 <li> 183 274 <label>Category Page </label> 184 275 <input type="text" name="cts" value="<?php echo get_option('ect_seo_cts',true)?>" style="width:666px"/><br /> 185 <code class="code">%SHOW_BLOG_NAME% store : %PROD_NAME% | %SEC_NAME% | %PROD_ID% | %CAT_NAME% </code>276 <code class="code">%SHOW_BLOG_NAME% store | %SEC_NAME% | %CAT_NAME% </code> 186 277 </li> 187 278 <li><input type="submit" value="Update Settings"/> … … 220 311 for($i=0;$i<count($_POST['seo_data_title']);$i++) 221 312 { 222 update_option('ect_seo_'.$PagesArr2[$i].'_title',$_POST['seo_data_title'][$ i]);223 update_option('ect_seo_'.$PagesArr2[$i].'_meta_description',$_POST['seo_data_metacnt'][$ i]);313 update_option('ect_seo_'.$PagesArr2[$i].'_title',$_POST['seo_data_title'][$PagesArr2[$i]]); 314 update_option('ect_seo_'.$PagesArr2[$i].'_meta_description',$_POST['seo_data_metacnt'][$PagesArr2[$i]]); 224 315 } 225 316 echo '<script type="text/javascript">window.location="admin.php?page=ect_seo&msg=1"</script>'; 226 317 } 227 228 } 229 } 230 231 function GenerateSeoTags($P,$DefTitle='',$DefDesc='',$DefKey='') 232 { 318 319 } 320 } 321 322 function GenerateSeoTags($P,$DefTitle='',$DefDesc='',$DefKey='',$type='t',$Off=false) 323 { 324 233 325 global $post; 234 326 global $pagetitle,$topsection,$sectionname,$sectiondescription,$productname,$productid,$productdescription; … … 236 328 $Meta=get_option('ect_seo_'.$P.'_meta_description'); 237 329 $Key=get_option('ect_seo_'.$P.'_meta_keywords'); 238 if($P==' categories' || $P=='products')330 if($P=='products' || $P=='categories') 239 331 { 240 332 if(empty($pagetitle) && isset($_GET['cat']) && !empty($_GET['cat'])) 241 333 $Title=$Meta=''; 242 334 } 335 if($Off) 336 $Title=''; 243 337 $Title =!empty($Title) ? $Title : $DefTitle; 244 338 $Meta =!empty($Meta) ? $Meta : $DefDesc; … … 250 344 $Title=$Title1; 251 345 if(!empty($post->ID) && !empty($Meta1)) 252 $Meta=$Meta1; 346 347 $Meta=$Meta1; 253 348 //echo $productname; 254 349 if(empty($Title)) 350 $Title=$post->post_title; 255 351 $T =str_replace("%SHOW_BLOG_NAME%",$BlogInfo,$Title); 256 352 $M =str_replace("%SHOW_BLOG_NAME%",$BlogInfo,$Meta); 257 353 $K =str_replace("%SHOW_BLOG_NAME%",$BlogInfo,$Key); 258 if(empty($P)) 259 { 260 return ' <title>'.$T.'</title> 261 <meta name="Description" content="'.$M.'" /> '; 262 } 354 355 356 263 357 $DynamicMetaPages=array('proddetail','products','categories'); 264 if(!empty($pagetitle)) 358 if($P=='front_page') 359 return ($type=='t') ? $T : $M; 360 elseif(!empty($Title)) 265 361 { 266 362 if(in_array($P,$DynamicMetaPages)) 267 363 { 268 364 $DescP=($P!='proddetail') ? $sectiondescription : $productdescription; 269 if(!empty($ pagetitle))365 if(!empty($Title)) 270 366 { 271 $Srh=array('%SHOW_BLOG_NAME%','%PROD_NAME%','%SEC_NAME%','%PROD_ID%','%CAT_NAME%'); 272 $BlogInfo=esc_attr(get_bloginfo('name', 'display')) ; 273 $Rep=array($BlogInfo,$productname,$sectionname,$productid,$Cat); 274 return "<title>".$pagetitle."</title> 275 <meta name='Description' content='".str_replace('"','"',$DescP)."' >"; 367 //$Srh=array('%SHOW_BLOG_NAME%','%PROD_NAME%','%SEC_NAME%','%PROD_ID%','%CAT_NAME%'); 368 //$BlogInfo=esc_attr(get_bloginfo('name', 'display')) ; 369 //$Rep=array($BlogInfo,$productname,$sectionname,$productid,$Cat); 370 return ($type=='t') ? $T : $M; 276 371 } 277 372 else … … 284 379 $ts=$productname . ", " . $sectionname; 285 380 } 286 return "<title>".$BlogInfo." store: ".$ts."</title> 287 <meta name='Description' content='".str_replace('"','"',$DescP)."' >"; 381 return ($type=='t') ? $T : $M; 288 382 } 289 383 } 290 } 291 else 292 { 293 return ' <title>'.$T.'</title> 294 <meta name="Description" content="'.$M.'" /> '; } 384 else 385 return ($type=='t') ? $T : $M; 386 } 387 else 388 { 389 390 return ($type=='t') ? $T : $M; 391 } 295 392 } 296 393 add_action( 'add_meta_boxes', 'ect_seo_box_fun' ); … … 310 407 <input type="text" name="ect_seo_title" value="'.get_option('ect_seo_'.$post->ID.'_title').'"/> 311 408 </li> 409 312 410 <li> 313 411 <label>Page Meta Description</label> -
ect-seo/trunk/readme.txt
r1477624 r1541826 4 4 Tags: Wordpress ecommerce, ecommerce, online store, sell products, shopping cart, wordpress store, wordpress shopping cart, ecommerce software, seo, meta description, title tag, search engine friendly, search engine optimization 5 5 Requires at least: 3 6 Tested up to: 4.6 7 Stable tag: 1. 36 Tested up to: 4.6.1 7 Stable tag: 1.4 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 55 55 <?php echo do_shortcode('[ect_seo]')?> 56 56 1. Save header.php and check your title and meta description tags on your store pages. 57 1. If there is no title code in header.php, enter the shortcode just before <?php wp_head(); ?> 57 58 58 59 == Frequently asked questions == … … 84 85 = 1.3 = 85 86 * Title and meta description tags for home page. April 23rd 2015. 87 = 1.4 = 88 * Support for header files with no title code. November 28 2016.
Note: See TracChangeset
for help on using the changeset viewer.