function seo_images_replace($matches)
{
    global $post, $seo;
    # take care of unsusal endings
    $matches[0] = preg_replace('|([\'"])[/ ]*$|', '\\1 /', $matches[0]);
    ### Normalize spacing around attributes.
    $matches[0] = preg_replace('/\\s*=\\s*/', '=', substr($matches[0], 0, strlen($matches[0]) - 2));
    ### Get source.
    preg_match('/src\\s*=\\s*([\'"])?((?(1).+?|[^\\s>]+))(?(1)\\1)/', $matches[0], $source);
    $saved = $source[2];
    ### Swap with file's base name.
    preg_match('%[^/]+(?=\\.[a-z]{3}\\z)%', $source[2], $source);
    ### Separate URL by attributes.
    $pieces = preg_split('/(\\w+=)/', $matches[0], -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
    ### Add missing pieces.
    if (!in_array('title=', $pieces) || $seo['override_title']) {
        $titletext = isset($source[0]) ? str_replace("[image_name]", $source[0], $seo['image_title']) : '';
        $titletext = seo_replace($titletext, (array) $post);
        if (!in_array('title=', $pieces)) {
            array_push($pieces, ' title="' . $titletext . '"');
        } else {
            $key = array_search('title=', $pieces);
            $pieces[$key + 1] = '"' . $titletext . '" ';
        }
    }
    if (!in_array('alt=', $pieces) || $seo['override_alt']) {
        $alttext = isset($source[0]) ? str_replace("[image_name]", $source[0], $seo['image_alt']) : '';
        $alttext = seo_replace($alttext, (array) $post);
        if (!in_array('alt=', $pieces)) {
            array_push($pieces, ' alt="' . $alttext . '"');
            if (is_page()) {
                $i = 1;
            }
        } else {
            $key = array_search('alt=', $pieces);
            $pieces[$key + 1] = '"' . $alttext . '" ';
        }
    }
    return implode('', $pieces) . ' /';
}
    function current_title()
    {
        global $page, $paged, $seo, $post;
        if (isset($seo['seo_on']) && $seo['seo_on']) {
            $keyword = "";
            $description = get_bloginfo('description');
            if (is_home() || is_front_page()) {
                $title = seo_replace($seo['home_title'], (array) $post);
                $description = seo_replace($seo['home_desc'], (array) $post);
                $keyword = seo_replace($seo['keyword_home'], (array) $post);
                if (is_page()) {
                    $seo_option = get_post_meta($post->ID, 'seo_options', true);
                    if (isset($seo_option['seo_title']) && $seo_option['seo_title'] != '') {
                        $title .= " " . seo_replace($seo_option['seo_title'], (array) $post);
                    }
                    if (isset($seo_option['seo_desc']) && $seo_option['seo_desc'] != '') {
                        $description .= " " . seo_replace($seo_option['seo_desc'], (array) $post);
                    }
                    if (isset($seo_option['seo_keyword']) && $seo_option['seo_keyword'] != '') {
                        $keyword .= " " . $seo_option['seo_keyword'];
                    }
                }
            } elseif (is_category()) {
                $title = seo_replace($seo['category_title'], (array) $post);
                $description = seo_replace($seo['category_desc'], (array) $post);
                $keyword = seo_replace($seo['keyword_category'], (array) $post);
            } elseif (is_tax()) {
                $title = seo_replace($seo['tax_title'], (array) $post);
                $description = seo_replace($seo['tax_desc'], (array) $post);
                $keyword = seo_replace($seo['keyword_tax'], (array) $post);
            } elseif (is_archive()) {
                $title = seo_replace($seo['archive_title'], (array) $post);
                $description = seo_replace($seo['archive_desc'], (array) $post);
                $keyword = isset($seo['keyword_archive']) ? seo_replace($seo['keyword_archive'], (array) $post) : "";
            } elseif (is_author()) {
                $title = seo_replace($seo['author_title'], (array) $post);
                $description = seo_replace($seo['author_desc'], (array) $post);
                $keyword = seo_replace($seo['keyword_author'], (array) $post);
            } elseif (is_search()) {
                $title = seo_replace($seo['search_title'], (array) $post);
                $description = seo_replace($seo['search_title'], (array) $post);
                $keyword = seo_replace($seo['keyword_search'], (array) $post);
            } elseif (is_404()) {
                $title = seo_replace($seo['404_title'], (array) $post);
                $description = seo_replace($seo['404_desc'], (array) $post);
                $keyword = seo_replace($seo['keyword_404'], (array) $post);
            } else {
                $seo_option = get_post_meta($post->ID, 'seo_options', true);
                if (isset($seo_option['seo_title']) && $seo_option['seo_title'] != '') {
                    $title = seo_replace($seo_option['seo_title'], (array) $post);
                } else {
                    if (is_page()) {
                        $title = seo_replace($seo['page_title'], (array) $post);
                    } elseif (is_singular('portfolios')) {
                        $title = seo_replace($seo['portfolio_title'], (array) $post);
                    } elseif (is_single()) {
                        $title = seo_replace($seo['post_title'], (array) $post);
                    }
                }
                if (isset($seo_option['seo_desc']) && $seo_option['seo_desc'] != '') {
                    $description = seo_replace($seo_option['seo_desc'], (array) $post);
                } else {
                    if (is_page()) {
                        $description = seo_replace($seo['page_desc'], (array) $post);
                    } elseif (is_singular('portfolios')) {
                        $description = seo_replace($seo['portfolio_desc'], (array) $post);
                    } elseif (is_single()) {
                        $description = seo_replace($seo['post_desc'], (array) $post);
                    }
                }
                if (is_singular('portfolios')) {
                    if (!isset($seo_option['seo_keyword']) || $seo_option['seo_keyword'] == "") {
                        if ($seo['category_keyword']) {
                            $keyword .= seo_replace('[term_title]', (array) $post);
                        }
                        if ($seo['title_keyword']) {
                            $keyword .= $keyword != '' ? ", " . str_replace(' ', ', ', $post->post_title) : str_replace(' ', ', ', $post->post_title);
                        }
                    } else {
                        $keyword = $seo_option['seo_keyword'];
                    }
                } elseif (is_single()) {
                    if (!isset($seo_option['seo_keyword']) || $seo_option['seo_keyword'] == "") {
                        if ($seo['category_keyword']) {
                            $keyword .= seo_replace('[category]', (array) $post);
                        }
                        if ($seo['tag_keyword']) {
                            $tag = seo_replace('[tag]', (array) $post);
                            $keyword .= $keyword != '' && $tag != '' ? ", " . $tag : ($keyword == '' ? $tag : "");
                        }
                        if ($seo['title_keyword']) {
                            $keyword .= $keyword != '' ? ", " . str_replace(' ', ', ', $post->post_title) : str_replace(' ', ', ', $post->post_title);
                        }
                    } else {
                        $keyword = $seo_option['seo_keyword'];
                    }
                } elseif (is_page()) {
                    if (!isset($seo_option['seo_keyword']) || $seo_option['seo_keyword'] == "") {
                        if ($seo['title_keyword']) {
                            $keyword .= $keyword != '' ? ", " . str_replace(' ', ', ', $post->post_title) : str_replace(' ', ', ', $post->post_title);
                        }
                    } else {
                        $keyword = $seo_option['seo_keyword'];
                    }
                }
            }
            print "<title>" . $title . "</title>";
            ?>

        <?php 
            print "<meta name=\"description\" content=\"" . $description . "\" />";
            ?>

        <?php 
            print "<meta name=\"keywords\" content=\"" . $keyword . "\" />\n";
        } else {
            print "<title>";
            wp_title('|', true, 'right');
            bloginfo('name');
            $site_description = get_bloginfo('description', 'display');
            if ($site_description && (is_home() || is_front_page())) {
                echo " | {$site_description}";
            }
            if ($paged >= 2 || $page >= 2) {
                echo ' | ' . sprintf(__('Page %s', 'themeton'), max($paged, $page));
            }
            print "</title>";
        }
    }