Title: Using a Button Image to Toggle Two Languages
Last modified: August 30, 2016

---

# Using a Button Image to Toggle Two Languages

 *  [Exguardi](https://wordpress.org/support/users/exguardi/)
 * (@exguardi)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/using-a-button-image-to-toggle-two-languages/)
 * Hello,
 * I understand that it is possible to create custom Transposh widgets, but I was
   unclear as to how I could use that (or some other) functionality to create a 
   simple button for my site that will toggle between two languages (English and
   Spanish). The dropdowns, etc provided are nice but given the site’s target audience
   a simple image toggle would be preferable.
 * Thanks for any advice!
 * [https://wordpress.org/plugins/transposh-translation-filter-for-wordpress/](https://wordpress.org/plugins/transposh-translation-filter-for-wordpress/)

Viewing 5 replies - 1 through 5 (of 5 total)

 *  Plugin Author [oferwald](https://wordpress.org/support/users/oferwald/)
 * (@oferwald)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/using-a-button-image-to-toggle-two-languages/#post-6645303)
 * Since you are just toggling, I suggest using the transposh_echo() function, this
   will probably be the quickest way, you may also follow the widget writing guide
   on our trac site
 *  Thread Starter [Exguardi](https://wordpress.org/support/users/exguardi/)
 * (@exguardi)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/using-a-button-image-to-toggle-two-languages/#post-6645310)
 * So my methodology should be as follows:
    1) Create a new widget directory and
   PHP file 2) echo the needed HTML in tp_widgets_do, e.g.
 * echo ‘<button type=”button”>’
    ??? <– Now I am doing ‘something’ with the ‘args’
   that contain data such as the list of languages and current language… how do 
   I set a new language when that button is clicked? echo ‘</button>’
 * 3) include any JavaScript or CSS content
 *  Plugin Author [oferwald](https://wordpress.org/support/users/oferwald/)
 * (@oferwald)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/using-a-button-image-to-toggle-two-languages/#post-6645478)
 * Hi,
 * Since you just want to toggle, do a simple if, if the language is xx show one
   button, otherwise show the other one, the button should link to the page with
   the other language,
 * Good luck,
 *  Thread Starter [Exguardi](https://wordpress.org/support/users/exguardi/)
 * (@exguardi)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/using-a-button-image-to-toggle-two-languages/#post-6645483)
 * OK, based on your suggestion and site examples I’ve got everything working as
   such to switch back and forth between my two languages:
 *     ```
       static function tp_widget_do($args) {
               echo '<input type="button" ';
               foreach ($args as $langrecord) {
                   if(!$langrecord['active']) {
                     echo 'onclick="location.href=\'' . $langrecord['url'] . '\';" ';
                     echo 'value="' . $langrecord['lang'] . '">';
                   }
               }
               echo '</button>';
           }
       ```
   
 * This works great to display a simple button with the name of the language to 
   switch to printed on it.
 * However, I noticed that the ‘set this language as default’ text just kind of 
   appears to the right of my button element; is it possible to style or alter this
   element? Or just automatically set the new language as the ‘default’ language
   for the user, so the next time they load the site it will default to that language?
   Maybe using the global plugin object?
 *  Thread Starter [Exguardi](https://wordpress.org/support/users/exguardi/)
 * (@exguardi)
 * [10 years, 6 months ago](https://wordpress.org/support/topic/using-a-button-image-to-toggle-two-languages/#post-6645545)
 * Hi,
 * Since I hadn’t heard back I had the thought that I could at least disable the
   showing of the ‘set as default language’ text using css– however I’m now realizing
   that applying CSS to the custom button does not seem to be working.
 * Even if I copy-paste some of the code from your other widget/css files directly
   it does not appear to be styled. I’m not sure how to troubleshoot this and would
   appreciate any insight.
 * For example, I have:
 *     ```
       echo "<div class=\"" . NO_TRANSLATE_CLASS . " transposh_flags\" >HELLO WORLD</div>";
               echo '<input type="button" class="tpw_image_toggle btn" ';
       ```
   
 * In a css file with the same name as the PHP file (tpw_image_toggle), I have the
   following:
 *     ```
       .transposh_flags {
            color: #FF69B4;
       }
   
       .btn {
            -webkit-border-radius: 15;
            -moz-border-radius: 15;
            border-radius: 15px;
            font-family: Arial;
            color: #000000;
            font-size: 20px;
            background: #dbeaff;
            padding: 10px 20px 10px 20px;
            text-decoration: none;
       }
       .btn:hover {
            background: #fff8dc;
            text-decoration: none;
       }
       ```
   
 * But the content displays no styling. Based on the widget writing guidelines I
   thought maybe adding:
 *     ```
       static function tp_widget_css($file, $dir, $url) {
             wp_enqueue_style("custom/tpw_image_toggle", "$url/widgets/custom/tpw_image_toggle.css", array(), TRANSPOSH_PLUGIN_VER);
           }
       ```
   
 * to the PHP file might help, but to no avail. What am I missing?

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Using a Button Image to Toggle Two Languages’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/transposh-translation-filter-for-
   wordpress_495166.svg)
 * [Transposh WordPress Translation](https://wordpress.org/plugins/transposh-translation-filter-for-wordpress/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/transposh-translation-filter-for-wordpress/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/transposh-translation-filter-for-wordpress/)
 * [Active Topics](https://wordpress.org/support/plugin/transposh-translation-filter-for-wordpress/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/transposh-translation-filter-for-wordpress/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/transposh-translation-filter-for-wordpress/reviews/)

 * 5 replies
 * 2 participants
 * Last reply from: [Exguardi](https://wordpress.org/support/users/exguardi/)
 * Last activity: [10 years, 6 months ago](https://wordpress.org/support/topic/using-a-button-image-to-toggle-two-languages/#post-6645545)
 * Status: not resolved