Web Development

Pass Country Name in English and Show Norway Translated Country Name using PHP function

Here is the PHP code, you can use it if you need it, the code courtesy is one of my valued client.

function en_country_to_no_country_code($country)
{

$countries = array(
'Afghanistan' => 'Afghanistan',
'Ålandsøyene' => 'Aland Islands',
'Albania' => 'Albania',
'Algerie' => 'Algeria',
'Amerikansk Samoa' => 'American Samoa',
'Andorra' => 'Andorra',
'Angola' => 'Angola',
'Anguilla' => 'Anguilla',
'Antarktis' => 'Antarctica',
'Antigua og Barbuda' => 'Antigua And Barbuda',
'Argentina' => 'Argentina',
'Armenia' => 'Armenia',
'Aruba' => 'Aruba',
'Australia' => 'Australia',
'Østerrike' => 'Austria',
'Aserbajdsjan' => 'Azerbaijan',
'Bahamas' => 'Bahamas',
'Bahrain' => 'Bahrain',
'Bangladesh' => 'Bangladesh',
'Barbados' => 'Barbados',
'Hviterussland' => 'Belarus',
'Belgia' => 'Belgium',
'Belize' => 'Belize',
'Benin' => 'Benin',
'Bermuda' => 'Bermuda',
'Bhutan' => 'Bhutan',
'Bolivia' => 'Bolivia',
'Bosnia-Hertsegovina' => 'Bosnia And Herzegovina',
'Botswana' => 'Botswana',
'Bouvetøya' => 'Bouvet Island',
'Brasil' => 'Brazil',
'Britisk territorium i det indiske hav' => 'British Indian Ocean Territory',
'Brunei Darussalam' => 'Brunei Darussalam',
'Bulgaria' => 'Bulgaria',
'Burkina Faso' => 'Burkina Faso',
'Burundi' => 'Burundi',
'Kambodsja' => 'Cambodia',
'Kamerun' => 'Cameroon',
'Canada' => 'Canada',
'Kapp Verde' => 'Cape Verde',
'Caymanøyene' => 'Cayman Islands',
'Den sentralafrikanske republikk'  => 'Central African Republic',
'Tsjad' => 'Chad',
'Chile' => 'Chile',
'Kina' => 'China',
'Juleøya' => 'Christmas Island',
'Kokosøyene (Keeling)' => 'Cocos (Keeling) Islands',
'Colombia' => 'Colombia',
'Komorene' => 'Comoros',
'Kongo' => 'Congo',
'Kongo, Den demokratiske republikken'  => 'Congo, Democratic Republic',
'Cookøyene' => 'Cook Islands',
'Costa Rica' => 'Costa Rica',
'Cote D\'Ivoire' => 'Cote D\'Ivoire',
'Kroatia' => 'Croatia',
'Cuba' => 'Cuba',
'Kypros' => 'Cyprus',
'Tsjekkia' => 'Czech Republic',
'Danmark' => 'Denmark',
'Djibouti' => 'Djibouti',
'Dominica' => 'Dominica',
'Den dominikanske republikk' => 'Dominican Republic',
'Ecuador' => 'Ecuador',
'Egypt' => 'Egypt',
'El Salvador' => 'El Salvador',
'Ekvatorial-Guinea' => 'Equatorial Guinea',
'Eritrea' => 'Eritrea',
'Estland' => 'Estonia',
'Etiopia' => 'Ethiopia',
'Falklandsøyene (Malvinas)' => 'Falkland Islands (Malvinas)',
'Færøyene' => 'Faroe Islands',
'Fiji' => 'Fiji',
'Finland' => 'Finland',
'Frankrike' => 'France',
'Fransk Guyana' => 'French Guiana',
'Fransk Polynesia' => 'French Polynesia',
'Franske sørlige territorier' => 'French Southern Territories',
'Gabon' => 'Gabon',
'Gambia' => 'Gambia',
'Georgia' => 'Georgia',
'Tyskland' => 'Germany',
'Ghana' => 'Ghana',
'Gibraltar' => 'Gibraltar',
'Hellas' => 'Greece',
'Grønland' => 'Greenland',
'Grenada' => 'Grenada',
'Guadeloupe' => 'Guadeloupe',
'Guam' => 'Guam',
'Guatemala' => 'Guatemala',
'Guernsey' => 'Guernsey',
'Guinea' => 'Guinea',
'Guinea-Bissau' => 'Guinea-Bissau',
'Guyana' => 'Guyana',
'Haiti' => 'Haiti',
'Heard Island og Mcdonald Islands' => 'Heard Island & Mcdonald Islands',
'Holy See(Vatikanstaten)' => 'Holy See (Vatican City State)',
'Honduras' => 'Honduras',
'Hong Kong' => 'Hong Kong',
'Ungarn' => 'Hungary',
'Island' => 'Iceland',
'India' => 'India',
'Indonesia' => 'Indonesia',
'Iran, Islamsk Republikk Av' => 'Iran, Islamic Republic Of',
'Irak' => 'Iraq',
'Irlanti' => 'Ireland',
'Mansaarella' => 'Isle Of Man',
'Israel' => 'Israel',
'Italia' => 'Italy',
'Jamaica' => 'Jamaica',
'Japan' => 'Japan',
'Jersey' => 'Jersey',
'Jordan' => 'Jordan',
'Kazakhstan' => 'Kazakhstan',
'Kenya' => 'Kenya',
'Kiribati' => 'Kiribati',
'Korea' => 'Korea',
'Kuwait' => 'Kuwait',
'Kirgisistan' => 'Kyrgyzstan',
'Lao' => 'Lao',
'Latvia' => 'Latvia',
'Libanon' => 'Lebanon',
'Lesotho' => 'Lesotho',
'Liberia' => 'Liberia',
'Libyske arabiske Jamahiriya' => 'Libyan Arab Jamahiriya',
'Liechtenstein' => 'Liechtenstein',
'Litauen' => 'Lithuania',
'Luxembourg' => 'Luxembourg',
'Macao' => 'Macao',
'Makedonia' => 'Macedonia',
'Madagaskar' => 'Madagascar',
'Malawi' => 'Malawi',
'Malaysia' => 'Malaysia',
'Maldivene' => 'Maldives',
'Mali' => 'Mali',
'Malta' => 'Malta',
'Marshalløyene' => 'Marshall Islands',
'Martinique' => 'Martinique',
'Mauritania' => 'Mauritania',
'Mauritius' => 'Mauritius',
'Mayotte' => 'Mayotte',
'Mexico' => 'Mexico',
'Mikronesia, fødererte stater' => 'Micronesia, Federated States Of',
'Moldova' => 'Moldova',
'Monaco' => 'Monaco',
'Mongolia' => 'Mongolia',
'Montenegro' => 'Montenegro',
'Montserrat' => 'Montserrat',
'Marokko' => 'Morocco',
'Mosambik' => 'Mozambique',
'Myanmar' => 'Myanmar',
'Namibia' => 'Namibia',
'Nauru' => 'Nauru',
'Nepal' => 'Nepal',
'Nederland' => 'Netherlands',
'De nederlandske Antillene' => 'Netherlands Antilles',
'Ny-Caledonia' => 'New Caledonia',
'New Zealand' => 'New Zealand',
'Nicaragua' => 'Nicaragua',
'Niger' => 'Niger',
'Nigeria' => 'Nigeria',
'Niue' => 'Niue',
'Norfolkøya' => 'Norfolk Island',
'Nord-Marianene' => 'Northern Mariana Islands',
'Norge' => 'Norway',
'Oman' => 'Oman',
'Pakistan' => 'Pakistan',
'Palau' => 'Palau',
'Palestinsk territorium, Okkupert' => 'Palestinian Territory, Occupied',
'Panama' => 'Panama',
'Papua Ny-Guinea' => 'Papua New Guinea',
'Paraguay' => 'Paraguay',
'Peru' => 'Peru',
'Filippinene' => 'Philippines',
'Pitcairn' => 'Pitcairn',
'Polen' => 'Poland',
'Portugal' => 'Portugal',
'Puerto Rico' => 'Puerto Rico',
'Qatar' => 'Qatar',
'Gjenforening' => 'Reunion',
'Romania' => 'Romania',
'Russland'  => 'Russian Federation',
'Rwanda' => 'Rwanda',
'Saint Barthelemy' => 'Saint Barthelemy',
'Saint Helena' => 'Saint Helena',
'Saint Kitts og Nevis' => 'Saint Kitts And Nevis',
'Saint Lucia' => 'Saint Lucia',
'Sankt Martin' => 'Saint Martin',
'Saint Pierre og Miquelon' => 'Saint Pierre And Miquelon',
'Saint Vincent og Grenadiner' => 'Saint Vincent And Grenadines',
'Samoa' => 'Samoa',
'San Marino' => 'San Marino',
'Sao Tome og Principe' => 'Sao Tome And Principe',
'Saudi-Arabia' => 'Saudi-Arabia',
'Senegal' => 'Senegal',
'Serbia' => 'Serbia',
'Seychellene',
'Sierra Leone' => 'Sierra Leone',
'Singapore' => 'Singapore',
'Slovakia' => 'Slovakia',
'Slovenia' => 'Slovenia',
'Salomonøyene' => 'Solomon Islands',
'Somalia' => 'Somalia',
'Sør-Afrika' => 'South Africa',
'South Georgia og Sandwich Isl.' => 'South Georgia And Sandwich Isl.',
'Spania' => 'Spain',
'Sri Lanka' => 'Sri Lanka',
'Sudan' => 'Sudan',
'Surinam' => 'Suriname',
'Svalbard og Jan Mayen' => 'Svalbard And Jan Mayen',
'Swazimaa' => 'Swaziland',
'Sverige' => 'Sweden',
'Sveits' => 'Switzerland',
'Den Syriske Arabiske Republikken' => 'Syrian Arab Republic',
'Taiwan' => 'Taiwan',
'Tadsjikistan' => 'Tajikistan',
'Tanzania' => 'Tanzania',
'Thailand' => 'Thailand',
'Timor-Leste' => 'Timor-Leste',
'Togo' => 'Togo',
'Tokelau' => 'Tokelau',
'Tonga' => 'Tonga',
'Trinidad og Tobago' => 'Trinidad And Tobago',
'Tunisia' => 'Tunisia',
'Tyrkia' => 'Turkey',
'Turkmenistan' => 'Turkmenistan',
'Turks- og Caicosøyene' => 'Turks And Caicos Islands',
'Tuvalu' => 'Tuvalu',
'Uganda' => 'Uganda',
'Ukraina' => 'Ukraine',
'De forente arabiske emirater' => 'United Arab Emirates',
'Storbritannia' => 'United Kingdom',
'Amerikas forente stater' => 'United States',
'Amerikas forente stater' => 'United States Outlying Islands',
'Uruguay' => 'Uruguay',
'Usbekistan' => 'Uzbekistan',
'Vanuatu' => 'Vanuatu',
'Venezuela' => 'Venezuela',
'Viet Nam' => 'Viet Nam',
'Jomfruøyene, Britisk' => 'Virgin Islands, British',
'Jomfruøyene, USA' => 'Jomfruøyene, USA',
'Wallis og Futuna' => 'Wallis And Futuna',
'Vest-Sahara' => 'Western Sahara',
'Jemen' => 'Yemen',
'Zambia' => 'Zambia',
'Zimbabwe' => 'Zimbabwe',
'NORD-AMERIKA' => 'NORTH AMERICA',
'EUROPA' => 'EUROPE',
'SØR-AMERIKA' => 'SOUTH AMERICA',
'ASIA' => 'ASIA',
'AFRIKA' => 'AFRICA',
'OSEANIA' => 'OCEANIA',
);

	// Set ISO
	$iso_code = strtolower(array_search(strtolower($country), array_map('strtolower', $countries)));

	return $iso_code;
}
WordPress Tricks

Show custom dropdown based on visited url in woocommerce category page

Suppose in some specific url ( mainly your product category page url) you want to show some specific or customize dropdown. Here I am sharing you such code which you can use by customizing it.

add_action( 'woocommerce_before_shop_loop', 'showcustomdropdown', 31 );
 
function showcustomdropdown() {      
   if ( is_product_category() ) {      
     // wc_product_dropdown_categories();
	$url = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];


if ((strpos($url,'?product_cat=wall-mounted+single-zone') !== false) || strpos($url,'?product_cat=floor-mounted+single-zone') !== false || strpos($url,'?product_cat=ceilling-cassettes+single-zone') !== false || strpos($url,'?product_cat=concealed-duct+single-zone') !== false || strpos($url,'/mini-split-ac/single-zone/') !== false)  {
	echo "<select id='product_cat'>";
	echo '<option value=" ">'."Select Category"."</option>"; 
   echo '<option value="?product_cat=wall-mounted+single-zone">'. "Wall Mounted" .  '</option>';
	echo '<option value="?product_cat=floor-mounted+single-zone">'."Floor Mounted"  .  '</option>';
	echo '<option value="?product_cat=ceilling-cassettes+single-zone">'. "Ceilling Cassettes" .  '</option>';
	echo '<option value="?product_cat=concealed-duct+single-zone">'. "Concealed Duct" .  '</option>';
	echo "</select>";
} else {
    
}
	   
   } 
   wc_enqueue_js( "
      $('#product_cat').change(function () {
         location.href = '/shop/' + $(this).val();
      });
   " );
}
Web Development

Remove Links and keep text in table or Div : Use it either for mobile or desktop

Suppose you have a table and you have information with links there. So in Desktop view you want to keep those information with links, but in mobile view you just want the information to show without wrapping links. Here is the JQuery code which i used to implement that. Basically i collected the code from stackoverflow and modified as per my requirements.

Here is the code

 <script>
$(document).ready(function() {
	  	 
	
	if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
		console.log(" mobile ");
  $('table tr td,table tr td').each(function(){
  
    if($(this).hasClass("nolink")){ 
    $(this).find("a").contents().unwrap();
    }
    });
}
});
 </script>
Karma Observation

What is the karma and curse associated with Child abortion?

Here I want to share you some of my thoughts regarding child abortion, the karma and curse associated with it.
So, if you are thinking of child abortion due to some reason ( or mistake in life) or you already faced it. Please read this carefully and share me your thoughts

Continue reading “What is the karma and curse associated with Child abortion?”
WordPress Tricks

WordPress theme Zoologist by Automattic: CSS Customization of header, footer, contents and more

Zoologist by Automattic
Image Courtesy WordPress.com

Zoologist  by Automattic is a simple single column theme. If you are searching for a single column layout theme with basic design then this theme can be a good choice for you. Here I am going to share you CSS tricks to modify header, footer, fonts style and more.

Live Demo of Zoologist by Automattic

If you want to install it in your self hosted wordpress site, you can download them from WordPress.com repository.

Download Zoologist Parent theme Blockbase

Download Zoologist Child theme

Also You need to Install Gutenberg Plugins by Gutenberg Team

So, Here I am sharing you the css tricks which you can use to change the style of the theme.

Continue reading “WordPress theme Zoologist by Automattic: CSS Customization of header, footer, contents and more”
WordPress Tricks

Custom Post Type archive template with pagination and Advance Custom Field value

Here I am sharing you a basic template to show Custom Post Type posts with pagination and also the values from Advance Custom Field plugins.

If you face any issue to implement it, feel free to do comments in the comments section.

<?php
/**
* Template Name: Custom Post Archive
*
* @package WordPress
 */
 get_header(); 
?>
<?php 
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(  
        'post_type' => 'herb_study',
        'post_status' => 'publish',
        'posts_per_page' =>3, 
         'paged' => $paged
       
    );

    $loop = new WP_Query( $args ); 
        
    while ( $loop->have_posts() ) : $loop->the_post(); 
?>

 
 
<?php 
if(get_field('Image',get_the_ID())){?>
<img src="<?php   echo get_field('Image',get_the_ID());?>"/>
<?php } ?>
 
 
 
 <?php endwhile;
 ?>


<span class="pagination"> 
 <?php
 echo paginate_links( array(
                   'total' => $loop->max_num_pages
               ) );
 
     ?>
</span>		
		 
        <?php  
   
    wp_reset_postdata();
?>

<?php get_footer(); ?>
WordPress Tricks

Solution of Fatal error: Uncaught Error: Call to undefined function gutenberg_block_template_part() in \wp-content\themes\blockbase-wpcom\header.php:16

So I tried to test the Zoologist theme by Automattic which is using Blockbase parent theme. But while trying to install, I found the theme showing this Fatal Error

Fatal Error Blockbase parent theme by Automattic

Solution

Please Install Gutenberg plugins by Gutenberg team . Click Here To Install Gutenberg Plugins and the issue will be solved

Gutenberg by Gutenberg Team
Web Development

Identify If you are not at the top of a webpage while it loads or refresh and add class to a Div or HTML Elements using jQuery

Suppose you are visiting a page and you scrolled to a portion of that page, now if you refresh or reload the page, you need to check you are not at the top of the website
and add a class to a HTML Elements. So This jQuery code will help you achieve this.

	<script>
	jQuery(document).ready(function(){
		 
 
    var windowpos = jQuery(window).scrollTop();
	console.log(windowpos);
      
      if(windowpos>100){
        jQuery('CLASS OR ID OF HTML ELEMENTS').addClass('CLASS YOU WANT TO ADD');
      }
 }); 	
 </script>
WordPress Tricks

If slug or portion of URL matched then redirect it to different URL using htaccess file.

Basically this is a solution of broken link in wordpress. As broken link cause issues in SEO, so you may need to redirect a bulk amount of urls to different url. So here I am sharing you a solution which basically I found working.

Client wanted to redirect all urls ( which was showing 404 error ) containing specific slug ( like category/success-story/) to be redirected to a different URL. Here is the code i used and put it in htaccess file of wordpress root folder.

<IfModule>
RewriteEngine on
RewriteRule ^(.*)url-slug/url-childslug(.*)$ https://www.your-site-url/page/about [L,R=301]
</IfModule>

Just replace the slugs and url as per your requirement.

Karma Observation

Question regarding exalted mars with Rahu in lagna: what it indicates and pending karma

What does exalted mars with Rahu in lagna indicate. What is the pending karma as Rahu is involved?? this is the question which native asked. So, I shared my thought to Native which i am sharing it for you too for learning purpose.

Continue reading “Question regarding exalted mars with Rahu in lagna: what it indicates and pending karma”