Redirect all url to https

If you have a secure certificate (SSL) on your website, you can automatically redirect visitors to the secured (HTTPS) version of your website to make sure their information is protected.

Using the following code in your .htaccess file automatically redirects visitors to the HTTPS version of your site:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

If you have an existing .htaccess file:

  • Do not duplicate RewriteEngine On.
  • Make sure the lines beginning RewriteCond and RewriteRule immediately follow the already-existing RewriteEngine On.

How To Create WordPress Shortcodes

WordPress introduced the shortcode API in version 2.5. Shortcodes are now used by a large number of WordPress plugins to allow users to add content to their posts and pages. All of us have probably used them at one time or another. They usually come bundled with plugins, or even themes, and what they do is watch for when you insert something inside square brackets then replace that with some other content; it could be a simple sentence or it could be a massive PHP function, it all depends on what you instructed WordPress to do.

The shortcode API allows you to create your own shortcodes by adding functions to your theme functions.php template (this is located at www.yourwebsite.com/wp-content/themes/yourtheme/).

In addition to creating your own shortcodes, WordPress also includes five default shortcodes with the WordPress core:
audio – Allows you to embed audio files.
caption – Allows you to wrap captions around content. It is commonly used with images.
embed – Allows you to embed a wide range of content such as video, audio and tweets.
gallery – Allows you to insert image galleries.
video – Allows you to embed video files.

In this article we will create some simple WordPress shortcodes to help you create any functionality you like.

A Basic Example

In our first example we want to create a shortcode that will create some “custom text” every time we type [spin2win] into the editor. First we need to create the callback function that will return the “custom text”

function spin2win_func() {
return “I am new shortcode text”;
}

Next we need to add this shortcode to WordPress using the add_shortcode function in either our functions.php file

add_shortcode( ‘spin2win’, ‘spin2win_func’ );

So the full code would be like this :

function spin2win_func() {
return “I am new shortcode text”;
}
add_shortcode( ‘spin2win’, ‘spin2win_func’ );

Note : spin2win_func and spin2win can be any name.

Creating a Shortcode With Attributes

Attributes can expand the functionality of shortcodes by allowing you to pass data through your shortcodes.

When WordPress encounters this we want a function that will insert an image. It needs to read the width and height attributes

function get_images($atts) {
extract(shortcode_atts(array(
‘width’ => 250,
‘height’ => 180,
), $atts));
return ‘‘;
}

add_shortcode(‘getpics’, ‘get_images’);

That’s all 🙂

Magento 500 internal server error

Today we will find out a solution troubleshooting Internal Server Error with Magento Store in any case for any reason. Many users encounter this weird Magento 500 Internal Server Errors. I will try to list the most common solutions. These errors are not always caused by the same reason. You should try to take a look at your server’s error logs to get some help about this error.

We can get info about the errors by Turning on Developer Mode. Look in the Magento bootstrap file (index.php), you will see lines similar to the following around line 63-67

#Mage::setIsDeveloperMode(true);
#ini_set(‘display_errors’, 1);

Uncomment these. In a production system, you’d never want to have your errors display to the browser, but while developing having an errors and warnings thrown immediately in your face is invaluable.
This way, you will see the actually problem which lead to the Internal Error Server. In almost cases, the reason is that there is an exception throw after output is sent to browser.

Sometime, this error is not visible and it just affect and make some Magento feature not working, for example this error just can be seen with Web Developer by tracking Ajax request and response. So here are a few possible reason
– Htaccess file which is located at Magento root folder. It will be this case if you meet Internal Server Error on every page. Try to remove it for testing purpose
If your website was running file for a long time, then it must be a change at Server side, just submit a ticket to Hosting Company.

If you are getting weird 500 internal server errors on specific pages of your site, it might be a matter of resources. I was getting internal server erros on some product pages and on the http://yourdomain.com/checkout/onepage. I found out that the .htacess file of my magento installation was somehow reset and the php_value memory_limit value was set to 32M as soon as I raised it, the internal server errors vanished! You should use at least 256M for over 600-700 SKUs. Magento is very resource hungry and it is easy to get these kind of errors if you try to save some bucks from the hosting.

Some cases the reason might be default permission on some hosting. To solve this go to File Manager and then change the file permission of index.php file from 664 to 644. Also change the permissions of downloader/index.php file to 644 as well otherwise when you will try to access System > Magento Connect >Magento Connect Manager (after magento installation) by logging to magento admin, you will get 500 Internal Server Error.

If the curl extension is missing you can get 500 Internal server error. You can install it using the command below:
apt-get install curl libcurl3 libcurl3-dev php5-curl

Media query for large screen

Here is media query for large screen. You can apply the breakpoints and enjoy the work.

@media screen and (min-width: 1400px) {

}
@media screen and (min-width: 1600px) {

}
@media screen and (min-width: 1900px) {

}

Settings defined in website scopes are ignored in magento2

Today I will show you how you can fix the Settings defined in website scopes are ignored.

This is a core bug in 2.1.3 – https://github.com/magento/magento2/issues/7943

The change you need to make is to vendor/magento/module-store/Model/Config/Processor/Fallback.php

Change this

/**
* Retrieve Website Config
*
* @param array $websites
* @param int $id
* @return array
*/
private function getWebsiteConfig(array $websites, $id)
{
foreach ($this->websiteData as $website) {
if ($website[‘website_id’] == $id) {
$code = $website[‘website_id’];
return isset($websites[$code]) ? $websites[$code] : [];
}
}
return [];
}
To

/**
* Retrieve Website Config
*
* @param array $websites
* @param int $id
* @return array
*/
private function getWebsiteConfig(array $websites, $id)
{
foreach ($this->websiteData as $website) {
if ($website[‘website_id’] == $id) {
$code = $website[‘code’];
return isset($websites[$code]) ? $websites[$code] : [];
}
}
return [];
}

Note the line

$code = $website[‘code’];

Redmi mobile suddenly not starting

Some people like me may get the issue of Redmi mobiles suddenly switched off and not booting. That’s really very irritating. In the mobile age I think no one can live without…. 🙂

So I tried to find the issue. First I tried to use another charger and no luck!! Whole day my mobile was switched off. I was thinking what Can I do… So I tried to connect mobile to my Laptop… but still no luck. That was not charging and not starting… I worried may be I have to go to Redmi customer service but once again I google on about this issue and find many tricks as I have applied above but no works.

Finally I found a solution and that worked for me, then I thought I have to write that on my blog.. May be this trick will work for other people…

Push Vol down and power for around 15 second, It will show MI BUNNY fastboot mode and press till vibrate!!

That’s it.

PS : The issue caused due to app/system hang.

Enable error reporting in joomla

Sometime is not easy to find the site issues. So we must have to enable the error reporting while in development. Joomla uses PHP and when PHP has problems, it reports them to you.

Here is short tutorial for enable error reporting in joomla.

1- Go to Site > Global Configuration > Server > Error Reporting.
2- You have five choices: System Default: this allows error reporting to be determined by the php.ini file on your server. Development will show all error reporting.

System Default this allows error reporting to be determined by the php.ini file on your server.
None will disable all error reporting.
Simple will show Errors and Warnings but won’t show Notices.
Maximum will show Errors, Warnings and Notices.
Development will literally overwhelm you with feedback. If you’re not a developer, please don’t use this option.

 

Disble error reporting in joomla

Sometime is not easy to find the site issues. So we must have to enable the error reporting while in development. Joomla uses PHP and when PHP has problems, it reports them to you. However, often these errors will appear on your site and will be visible to visitors. So we must have to disable theme.

Here is short tutorial for enable or disable error reporting in joomla.

1- Go to Site > Global Configuration > Server > Error Reporting.
2- You have five choices: System Default: this allows error reporting to be determined by the php.ini file on your server. None will disable all error reporting.

System Default this allows error reporting to be determined by the php.ini file on your server.
None will disable all error reporting.
Simple will show Errors and Warnings but won’t show Notices.
Maximum will show Errors, Warnings and Notices.
Development will literally overwhelm you with feedback. If you’re not a developer, please don’t use this option.

How to change continue reading link text in wordpress

How to change continue reading link text in wordpress. In this tutorial I will show you how you can change the “continue reading” text in wordpress. If you want to modify continue reading link with Read more , you can use this function in your functions.php file.

function my_code_excerpt_more( $more ) {
return ‘ ‘ . __(‘Read More’, ‘your-text-domain’) . ‘‘;
}
add_filter( ‘excerpt_more’, ‘my_code_excerpt_more’ );

May be your theme does have another text except “continue reading”, so this trick also will work for those.

How to change length of post excerpt in wordpress theme

In this case here is little code and that will help!! You will have to use the code in functions.php file

/* Changed excerpt length to 200 words*/
function your_code_excerpt_length( $length ) {
return 20;
}
add_filter( ‘excerpt_length’, ‘your_code_excerpt_length’, 200 );

If you are not ok with the limit of 200, you can change to to any integer number you like.