Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to Add SEO Meta Tags in Wordpress without Plugins

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 1
    • 0
    • 610
    Comment on it

    Hello Guys,

    There are number of click plugins available on internet for your seo needs but most of them have many complex function for simple needs. I am not saying that there is no good SEO plugins in the market but they are few like All in One SEO PACK and WordPress SEO by Yoast.

    Wordpress without Plugins

    What are Meta Tags ?

    Meta tags is responsible for providing the information like Title, Description, keywords etc to various Search engines like Google, Bing yahoo etc. This simple tutorial will guide you to just put some easy set of codes in function.php and header.php files of WordPress.

    • Paste the below code in functions.php file

    • Put your own Keywords instead of $default_keywords .

    • Add a Just one line code in the head section of header.php

    • Tune the Below code according to your website source code.

    function basic_wp_seo() {
        global $page, $paged, $post;
        $default_keywords = 'Php Developer forum, Php questions and answers, Java, iphone, Android developer forum'; // customize
        $output = '';
    
        // description
        $seo_desc = get_post_meta($post->ID, 'mm_seo_desc', true);
        $description = get_bloginfo('description', 'display');
        $pagedata = get_post($post->ID);
        if (is_singular()) {
            if (!empty($seo_desc)) {
                $content = $seo_desc;
            } else if (!empty($pagedata)) {
                $content = apply_filters('the_excerpt_rss', $pagedata->post_content);
                $content = substr(trim(strip_tags($content)), 0, 155);
                $content = preg_replace('#\n#', ' ', $content);
                $content = preg_replace('#\s{2,}#', ' ', $content);
                $content = trim($content);
            } 
        } else {
            $content = $description;  
        }
        $output .= '<meta name="description" content="' . esc_attr($content) . '">' . "\n";
    
        // keywords
        $keys = get_post_meta($post->ID, 'mm_seo_keywords', true);
        $cats = get_the_category();
        $tags = get_the_tags();
        if (empty($keys)) {
            if (!empty($cats)) foreach($cats as $cat) $keys .= $cat->name . ', ';
            if (!empty($tags)) foreach($tags as $tag) $keys .= $tag->name . ', ';
            $keys .= $default_keywords;
        }
        $output .= "\t\t" . '<meta name="keywords" content="' . esc_attr($keys) . '">' . "\n";
    
        // robots
        if (is_category() || is_tag()) {
            $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
            if ($paged > 1) {
                $output .=  "\t\t" . '<meta name="robots" content="noindex,follow">' . "\n";
            } else {
                $output .=  "\t\t" . '<meta name="robots" content="index,follow">' . "\n";
            }
        } else if (is_home() || is_singular()) {
            $output .=  "\t\t" . '<meta name="robots" content="index,follow">' . "\n";
        } else {
            $output .= "\t\t" . '<meta name="robots" content="noindex,follow">' . "\n";
        }
    
        // title
        $title_custom = get_post_meta($post->ID, 'mm_seo_title', true);
        $url = ltrim(esc_url($_SERVER['REQUEST_URI']), '/');
        $name = get_bloginfo('name', 'display');
        $title = trim(wp_title('', false));
        $cat = single_cat_title('', false);
        $tag = single_tag_title('', false);
        $search = get_search_query();
    
        if (!empty($title_custom)) $title = $title_custom;
        if ($paged >= 2 || $page >= 2) $page_number = ' | ' . sprintf('Page %s', max($paged, $page));
        else $page_number = '';
    
        if (is_home() || is_front_page()) $seo_title = $name . ' | ' . $description;
        elseif (is_singular())            $seo_title = $title . ' | ' . $name;
        elseif (is_tag())                 $seo_title = 'Tag Archive: ' . $tag . ' | ' . $name;
        elseif (is_category())            $seo_title = 'Category Archive: ' . $cat . ' | ' . $name;
        elseif (is_archive())             $seo_title = 'Archive: ' . $title . ' | ' . $name;
        elseif (is_search())              $seo_title = 'Search: ' . $search . ' | ' . $name;
        elseif (is_404())                 $seo_title = '404 - Not Found: ' . $url . ' | ' . $name;
        else                              $seo_title = $name . ' | ' . $description;
    
        $output .= "\t\t" . '<title>' . esc_attr($seo_title . $page_number) . '</title>' . "\n";
    
        return $output;
    }
    

    Source: seo without plugin


    This is all from my side,you can Drop your queries regarding this Blog at our Php questions and Answers Forum

    How to Add SEO Meta Tags in Wordpress without Plugins

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: