• Resolved antosassi

    (@antosassi)


    The featured images shown in the front page slider are showing as alternative text the post title, and as I am using qtranslate it shows the name in all the current languages being used (spanish and english) with the corresponding attribute <!–:en–>. How can I change this? Is it possible to control this? I already double checked the featured-content.php and I don’t seem to find where to adjust this.

    Example:
    Alt Text for featured image on slider: <!–:en–>Barva Volcano<!–:–><!–:es–>Volcán Barva<!–:–>

    Thanks!

Viewing 9 replies - 1 through 9 (of 9 total)
  • Thread Starter antosassi

    (@antosassi)

    Does someone have the same problem? Great to hear your thoughts on how to solve this. Thank you!

    Here the link to my trail site: https://www.360travelagency.com/prueba/

    I also had the same problem recently and just wrote an article on my blog on how to solve that.

    I hope you will find it useful.

    Thread Starter antosassi

    (@antosassi)

    Hi there!! Thank you for answering. I found your post very clear, unfortunately I still can’t find the correct place to add the lines you suggest. Should it be on featured-content.php, post.php or someplace else?

    The only thing I found was this:

    <div class="featured-post">
    <?php if ( current_theme_supports( 'get-the-image' ) ) get_the_image( array( 'meta_key' => 'Thumbnail', 'size' => 'featured-thumbnail' ) ); ?>
    <h2 class="post-title entry-title">
    <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
    </h2>
    </div> <!-- .featured-post -->

    Goes without saying that I don’t know much about code, therefore I really appreciate if you can help me locate this. Please let me know if you need me to copy something here.

    Thank you!

    My blog post is about how to make alt-text that the_post_thumbnail() produces support different languages.

    Your problem differs a little since you wrote “The featured images shown in the front page slider “.

    So first you need to figure out which template front page uses and then locate code that outputs alternative text in that slider. Once you find it, try putting that code as parameter for _e() function. This should filter the text, so that only language for the current language will be used.

    To learn more about _e() check this WordPress Codex Page.

    If you still have trouble solving your problem, you can try to get into contact with me using social icons on my blog and I will try to help out.

    Thread Starter antosassi

    (@antosassi)

    The whole problem is exactly that I can not locate the code that outputs the alternative text on the slider. I’ve searched on all related templates (featured-content.php, page-template-front.php, post.php) and I still don’t find where.

    The page Current Theme is Oxygen. I appreciate any help you can give!

    You were right all along. Code that creates the problematic alternative text is

    <?php if ( current_theme_supports( 'get-the-image' ) ) get_the_image( array( 'meta_key' => 'Thumbnail', 'size' => 'featured-thumbnail' ) );

    That get-the-image function was really hidden. I located it at

    Themes\oxygen\library\extensions\get-the-image.php

    Inside it at around line 400 or so you will find the following code:

    /* If there is alt text, set it.  Otherwise, default to the post title. */
    	$image_alt = ( ( !empty( $image['alt'] ) ) ? $image['alt'] : get_post_field( 'post_title', $post_id ) );

    After that line add this:

    $image_alt=__($image_alt);

    Then there are two more places, where alternative text is set like this:

    $alt=trim....

    You can do the same with them but I suspect the $image_alt is the one you need to fix.

    I am curious if this will fix the issue, so keep me informed:)

    Thread Starter antosassi

    (@antosassi)

    mmmm unfortunately that didn’t do it either. I tried adding the line, replacing it, erasing it completely, nothing changed. Is there a way not to have alt text? I rather have no alt text than this funny alt text with all the languages!! Thank you!

    Have you looked into the source code and checked what value alt text have?

    Or are you assuming it doesn’t work because when you hover over the image, the text does not get translated.

    I tested that theme and also thought that nothing got changed but then remembered that hover effect is created with a title tag so we need to make those changes for that tag too.

    Find this code around line 420

    /* If $link_to_post is set to true, link the image to its post. */
    	if ( $link_to_post )
    		$html = '<a href="' . get_permalink( $post_id ) . '" title="' . esc_attr( get_post_field( 'post_title', $post_id ) ) . '">' . $html . '</a>';

    And replace it with this:

    /* If $link_to_post is set to true, link the image to its post. */
    	if ( $link_to_post )
    	{
    	    $title=__(get_post_field( 'post_title', $post_id ));
    		$html = '<a href="' . get_permalink( $post_id ) . '" title="' . esc_attr( $title ) . '">' . $html . '</a>';
        }
    Thread Starter antosassi

    (@antosassi)

    Now it works, thank you very much!!! I thought about this, but would have never been able to write the necessary line of code. Thanks again!! ??

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Change alternative text for featured images when using qtranslate’ is closed to new replies.