WordPress.org

Ready to get started?Download WordPress

Forums

WordPress SEO by Yoast
WordPress SEO 1.5.2.1 with QTranslate (8 posts)

  1. 3Lancer
    Member
    Posted 5 months ago #

    I'm currently attempting to merge the qTranslate plugin to work with WordPress SEO 1.5.2.1.

    Under my theme's 'functions.php' added:

    // Enable qTranslate for WordPress SEO
    if(defined("QT_SUPPORTED_WP_VERSION")) {
    	function qtranslate_filter($text){
    		return __($text);
    	}
    	add_filter('wpseo_title', 'qtranslate_filter', 10, 1);
    	add_filter('wpseo_metadesc', 'qtranslate_filter', 10, 1);
    	add_filter('wpseo_metakey', 'qtranslate_filter', 10, 1);
    	add_filter('wpseo_opengraph_title', 'qtranslate_filter', 10, 1);
    }

    Then under the plugin itself 'js/wp-seo-metabox.js' and 'js/wp-seo-metabox.min.js', attempting to inject this function:

    function qtranslateParse(text){
        //\[:en\](.*?)([^\[]+)
        var result = text;
        var reg1 = new RegExp("<!--:" + wpseo_lang + "-->(.*?)<!--:-->");
        var match = reg1.exec(text, "gim");
        if (match != null)
            result = match[1];
    
        return result;
    }

    I use to be able to call this into the UpdateTitle, etc, such as:

    function updateTitle(force) {
    	if (jQuery("#yoast_wpseo_title").val()) {
    		var title = qtranslateParse(jQuery("#yoast_wpseo_title").val());
    	} else {
    		var title = wpseo_title_template.replace('%%title%%', qtranslateParse(jQuery('#title').val()));
    		title = jQuery('<div />').html(title).text();
    	}

    Which would ensure it would only display one language under the SEO Title. The issue I have with the latest update is this is been changed and my calls tend to cause the SEO Title is disappear completely?

    https://wordpress.org/plugins/wordpress-seo/

  2. 3Lancer
    Member
    Posted 5 months ago #

    No one else using QTranslate with the later version of Yoast SEO?

  3. leslierad
    Member
    Posted 5 months ago #

    I have the same issue as you, with WordPress SEO 1.5.2.2, try the below into js/wp-seo-metabox.min.js:

    function updateTitle(force) {
    	var title = '';
    	var titleElm = qtranslateParse(jQuery('#'+wpseoMetaboxL10n.field_prefix+'title'));
    	var titleLengthElm = qtranslateParse(jQuery('#'+wpseoMetaboxL10n.field_prefix+'title-length'));
    	var divHtml = jQuery('<div />');
    	var snippetTitle = jQuery('#wpseosnippet').find('.title');

    My issue is that it strips the [en:]and langs from the meta description, the rest seems ok, but I know the author does not support qtranslate unfortunately.

  4. 3Lancer
    Member
    Posted 5 months ago #

    Thanks for your reply, but no luck from that.

    Seems -

    title = wpseoMetaboxL10n.wpseo_title_template.replace('%%title%%', jQuery('#title').val());
    title = divHtml.html(title).text();

    Gets upset with that 'qtranslateParse' call and displays nothing for the SEO Title.

    ps: I don't think you need it on 'titleLengthElm' as well?

  5. 3Lancer
    Member
    Posted 5 months ago #

    Anyone? this is quite important (upgrading of this plugin at a stop).

    I see the issue is that the title, before it's even called into the 'js/wp-seo-metabox.js' is already stripped of it's qTranslate tags, therefore you simply get multiple titles (for example stripped: title 1title 2title 3title 4title 5) or nothing at all.

    I need to know where it's doing that stripping of the '#title' and why it's different that the rest which seems to work fine?

  6. leslierad
    Member
    Posted 5 months ago #

    Ok, here's what I have so far, please share any changes you make:

    WPSEO ver. 1.5.2.5

    \wordpress-seo\js\wp-seo-metabox.js
    line 279

    -- var desc = jQuery.trim(yst_clean(descElm.val()));
    ++ var desc = jQuery.trim(descElm.val());

    save wp-seo-metabox.js as wp-seo-metabox.min.js

    in theme folder add to functions.php

    // Enable qTranslate for WordPress SEO
    if(defined("QT_SUPPORTED_WP_VERSION")) {
    	function qtranslate_filter($text){
    		return __($text);
    	}
    	add_filter('wpseo_title', 'qtranslate_filter', 10, 1);
    	add_filter('wpseo_metadesc', 'qtranslate_filter', 10, 1);
    	add_filter('wpseo_metakey', 'qtranslate_filter', 10, 1);
    	add_filter('wpseo_opengraph_title', 'qtranslate_filter', 10, 1);
    }
    function wpseo_qtranslate4($post_content) {
    if(function_exists('qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage')) $post_content = qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($post_content);
    return $post_content;
    }
    add_filter('wpseo_heading_title4', 'wpseo_qtranslate4');

    \wp-content\plugins\wordpress-seo\admin\class-metabox.php
    line 1872

    -- $post_content = apply_filters( 'wpseo_pre_analysis_post_content', $post->post_content, $post );
    
    ++ $post_content = apply_filters( 'wpseo_heading_title4', $post->post_content, $post );

    This change is better to use original filter but when I was testing I used the changes listed and it seems to work.

    another filter on line 1138 haven't tested it yet.

    with the changes above the Page analysis seems to work also I only see 1 lang in snippet preview, but focus keyword count is wrong.

    I can see all langs in seo title and meta description.

    If you or anyone else have further changes or improvements please add them.

    Sitemaps for langs changes:

    class-sitemaps.php (wordpress-seo/inc/) only add //Leslie ( some of the code around has been changed but you will see where to add it, thats why I left extra lines in place, also change yoursite.com, add/ remove langs as needed.)

    if ( $n == 1 ) {
    			$front_id = get_option( 'page_on_front' );
    			if ( ! $front_id && ( $post_type == 'post' || $post_type == 'page' ) ) {
    				$output .= $this->sitemap_url( array(
    					'loc' => home_url( '/' ),
    					'pri' => 1,
    					'chf' => 'daily',
    				) );
                    // Leslie Start - Home Page Langs in Page
                    $output .= $this->sitemap_url( array(
    					'loc' => home_url( '/da/' ),
    					'pri' => 0.9,
    					'chf' => 'daily',
    				) );
                    $output .= $this->sitemap_url( array(
    					'loc' => home_url( '/de/' ),
    					'pri' => 0.9,
    					'chf' => 'daily',
    				) );
                    $output .= $this->sitemap_url( array(
    					'loc' => home_url( '/es/' ),
    					'pri' => 0.9,
    					'chf' => 'daily',
    				) );
                    $output .= $this->sitemap_url( array(
    					'loc' => home_url( '/no/' ),
    					'pri' => 0.9,
    					'chf' => 'daily',
    				) );
                    $output .= $this->sitemap_url( array(
    					'loc' => home_url( '/pt/' ),
    					'pri' => 0.9,
    					'chf' => 'daily',
    				) );
                    $output .= $this->sitemap_url( array(
    					'loc' => home_url( '/sv/' ),
    					'pri' => 0.9,
    					'chf' => 'daily',
    				) );
                    $output .= $this->sitemap_url( array(
    					'loc' => home_url( '/fr/' ),
    					'pri' => 0.9,
    					'chf' => 'daily',
    				) );
                    $output .= $this->sitemap_url( array(
    					'loc' => home_url( '/nl/' ),
    					'pri' => 0.9,
    					'chf' => 'daily',
    				) );
                    $output .= $this->sitemap_url( array(
    					'loc' => home_url( '/it/' ),
    					'pri' => 0.9,
    					'chf' => 'daily',
    				) );
                    // Leslie End
    			}
    			else if ( $front_id && $post_type == 'post' ) {
    $url['images'] = apply_filters( 'wpseo_sitemap_urlimages', $url['images'], $p->ID );
    
    				if ( ! in_array( $url['loc'], $stackedurls ) ) {
    					// Use this filter to adjust the entry before it gets added to the sitemap
    					$url = apply_filters( 'wpseo_sitemap_entry', $url, 'post', $p );
    					if ( ! empty( $url ) ) {
    						$output .= $this->sitemap_url( $url );
                            // Leslie Start - Posts & Pages
                            // $output = str_replace(">0.6<", ">0.5<", $output);
                            $url = str_replace("yoursite.com/", "yoursite.com/da/", $url);
                            $output .= $this->sitemap_url( $url );
                            $url = str_replace("/da/", "/de/", $url);
                            $output .= $this->sitemap_url( $url );
                            $url = str_replace("/de/", "/es/", $url);
                            $output .= $this->sitemap_url( $url );
                            $url = str_replace("/es/", "/no/", $url);
                            $output .= $this->sitemap_url( $url );
                            $url = str_replace("/no/", "/pt/", $url);
                            $output .= $this->sitemap_url( $url );
                            $url = str_replace("/pt/", "/sv/", $url);
                            $output .= $this->sitemap_url( $url );
                            $url = str_replace("/sv/", "/fr/", $url);
                            $output .= $this->sitemap_url( $url );
                            $url = str_replace("/fr/", "/nl/", $url);
                            $output .= $this->sitemap_url( $url );
                            $url = str_replace("/nl/", "/it/", $url);
                            $output .= $this->sitemap_url( $url );
    						// Leslie End
                            $stackedurls[] = $url['loc'];
    					}
    				}
    
    				// Clear the post_meta and the term cache for the post, as we no longer need it now.
    				// wp_cache_delete( $p->ID, 'post_meta' );
    				// clean_object_term_cache( $p->ID, $post_type );
    $url['mod'] = $wpdb->get_var( $sql );
    			$url['chf'] = 'weekly';
    
    			// Use this filter to adjust the entry before it gets added to the sitemap
    			$url = apply_filters( 'wpseo_sitemap_entry', $url, 'term', $c );
    
    			if ( ! empty( $url ) )
    				$output .= $this->sitemap_url( $url );
                    // Leslie Start -Category
                    // $output = str_replace(">0.6<", ">0.5<", $output);
                            $url = str_replace("yoursite.com/", "yoursite.com/da/", $url);
                            $output .= $this->sitemap_url( $url );
                            $url = str_replace("/da/", "/de/", $url);
                            $output .= $this->sitemap_url( $url );
                            $url = str_replace("/de/", "/es/", $url);
                            $output .= $this->sitemap_url( $url );
                            $url = str_replace("/es/", "/no/", $url);
                            $output .= $this->sitemap_url( $url );
                            $url = str_replace("/no/", "/pt/", $url);
                            $output .= $this->sitemap_url( $url );
                            $url = str_replace("/pt/", "/sv/", $url);
                            $output .= $this->sitemap_url( $url );
                            $url = str_replace("/sv/", "/fr/", $url);
                            $output .= $this->sitemap_url( $url );
                            $url = str_replace("/fr/", "/nl/", $url);
                            $output .= $this->sitemap_url( $url );
                            $url = str_replace("/nl/", "/it/", $url);
                            $output .= $this->sitemap_url( $url );
    						// Leslie End
    		}
    
    		if ( empty( $output ) ) {
    			$this->bad_sitemap = true;
    			return;
    		}
    
    		$this->sitemap = '<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ';
    		$this->sitemap .= 'xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" ';
    		$this->sitemap .= 'xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . "\n";
    		$this->sitemap .= $output . '</urlset>';
    	}
    
    	/**
    	 * Build the sub-sitemap for authors
    $this->sitemap = '<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" ';
    		$this->sitemap .= 'xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" ';
    		$this->sitemap .= 'xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . "\n";
    		$this->sitemap .= $output;
            // Leslie Start -Authors
            $output = str_replace("ty>0.8</pr", "ty>0.5</pr", $output);
            $output = str_replace("yoursite.com/", "yoursite.com/da/", $output);
            $this->sitemap .= $output;
            $output = str_replace("/da/", "/de/", $output);
            $this->sitemap .= $output;
            $output = str_replace("/de/", "/es/", $output);
            $this->sitemap .= $output;
            $output = str_replace("/es/", "/no/", $output);
            $this->sitemap .= $output;
            $output = str_replace("/no/", "/pt/", $output);
            $this->sitemap .= $output;
            $output = str_replace("/pt/", "/sv/", $output);
            $this->sitemap .= $output;
            $output = str_replace("/sv/", "/fr/", $output);
            $this->sitemap .= $output;
            $output = str_replace("/fr/", "/nl/", $output);
            $this->sitemap .= $output;
            $output = str_replace("/nl/", "/it/", $output);
            $this->sitemap .= $output;
            // Leslie End
    
    		// Filter to allow adding extra URLs, only do this on the first XML sitemap, not on all.
    		if ( $n == 0 )
    			$this->sitemap .= apply_filters( 'wpseo_sitemap_author_content', '' );
    
    		$this->sitemap .= '</urlset>';
    	}
    
    	/**
    	 * Spits out the XSL for the XML sitemap.

    Comment out images

    //if ( isset( $url['images'] ) && count( $url['images'] ) > 0 ) {
    		//	foreach ( $url['images'] as $img ) {
    		//		if ( ! isset( $img['src'] ) || empty( $img['src'] ) )
    		//			continue;
    		//		$output .= "\t\t<image:image>\n";
    		//		$output .= "\t\t\t<image:loc>" . esc_html( $img['src'] ) . "</image:loc>\n";
    		//		if ( isset( $img['title'] ) && ! empty( $img['title'] ) )
    		//			$output .= "\t\t\t<image:title>" . _wp_specialchars( html_entity_decode( $img['title'], ENT_QUOTES, get_bloginfo( 'charset' ) ) ) . "</image:title>\n";
    		//		if ( isset( $img['alt'] ) && ! empty( $img['alt'] ) )
    		//			$output .= "\t\t\t<image:caption>" . _wp_specialchars( html_entity_decode( $img['alt'], ENT_QUOTES, get_bloginfo( 'charset' ) ) ) . "</image:caption>\n";
    		//		$output .= "\t\t</image:image>\n";
    		//	}
    		//}
  7. b_machuel
    Member
    Posted 5 months ago #

    I am strongly interested in any successful follow-up to this problem, which currently affects 2 of my websites.

    Benoît
    ———

  8. 3Lancer
    Member
    Posted 4 months ago #

    Bump - this still appears to be an annoying issue, just for SEO titles in the Posts/Pages with QTranslate?

Reply

You must log in to post.

About this Plugin

About this Topic

Tags