9 hacks and snippets to extend WordPress functionality

Shortcode to display external files

If you need to display external files without posts or pages, here’s a useful shortcode to help. The code below goes into your theme’s functions.php:

function show_file_func( $atts ) {
  extract( shortcode_atts( array(
    'file' => ''
  ), $atts ) );
 
  if ($file!='')
    return @file_get_contents($file);
}
 
add_shortcode( 'show_file', 'show_file_func' );

And here’s how you use it:

[show_file file="https://catswhocode.com/blog"]

Source: Specky Boy

Remove featured image when deleting a post

The code below will automatically delete the featured image associated with a post, when the post in question is deleted. Just insert it into functions.php.

add_action( 'before_delete_post', 'wps_remove_attachment_with_post', 10 );
function wps_remove_attachment_with_post($post_id) {
        if(has_post_thumbnail( $post_id ))
        {
          $attachment_id = get_post_thumbnail_id( $post_id );
          wp_delete_attachment($attachment_id, true);
        }
}

Source: WP Snipp

Set default fallback thumbnail for featured images

This handy code snippet allows you to define a default fallback image for posts where a featured image isn’t defined.

This code has to be pasted anywhere you want the featured image or its fallback to be displayed, most commonly on index.php and single.php. Edit line 4 and replace the URL with the URL of your fallback image.

<?php if ( has_post_thumbnail() ) {
the_post_thumbnail();
} else { ?>
<img src="<?php bloginfo('template_directory'); ?>/images/default-image.jpg" alt="<?php the_title(); ?>" />
<?php } ?>

Source: WP Expertz

Manually move scripts and CSS files to the footer

In order to optimize your website speed, you sometimes might want to move scripts and stylesheet on the footer of your site. This example features how to do it on a WordPress blog, but any developer with a little bit of experience can modify the code to make it fit any kind of website.

First, open your functions.php file and paste the following code in it:

/**
 * Filter HTML code and leave allowed/disallowed tags only
 *
 * @param string 	$text 	Input HTML code.
 * @param string 	$tags 	Filtered tags.
 * @param bool 		$invert Define whether should leave or remove tags.
 * @return string Filtered tags
 */
function theme_strip_tags_content($text, $tags = '', $invert = false) {

    preg_match_all( '/<(.+?)[\s]*\/?[\s]*>/si', trim( $tags ), $tags );
    $tags = array_unique( $tags[1] );

    if ( is_array( $tags ) AND count( $tags ) > 0 ) {
        if ( false == $invert ) {
            return preg_replace( '@<(?!(?:'. implode( '|', $tags ) .')\b)(\w+)\b.*?>.*?</\1>@si', '', $text );
        }
        else {
            return preg_replace( '@<('. implode( '|', $tags ) .')\b.*?>.*?</\1>@si', '', $text );
        }
    }
    elseif ( false == $invert ) {
        return preg_replace( '@<(\w+)\b.*?>.*?</\1>@si', '', $text );
    }

    return $text;
}

/**
 * Generate script tags from given source code
 *
 * @param string $source HTML code.
 * @return string Filtered HTML code with script tags only
 */
function theme_insert_js($source) {

    $out = '';

    $fragment = new DOMDocument();
    $fragment->loadHTML( $source );

    $xp = new DOMXPath( $fragment );
    $result = $xp->query( '//script' );

    $scripts = array();
    $scripts_src = array();
    foreach ( $result as $key => $el ) {
        $src = $result->item( $key )->attributes->getNamedItem( 'src' )->value;
        if ( ! empty( $src ) ) {
            $scripts_src[] = $src;
        } else {
            $type = $result->item( $key )->attributes->getNamedItem( 'type' )->value;
            if ( empty( $type ) ) {
                $type = 'text/javascript';
            }

            $scripts[$type][] = $el->nodeValue;
        }
    }

    //used by inline code and rich snippets type like application/ld+json
    foreach ( $scripts as $key => $value ) {
        $out .= '<script type="'.$key.'">';

        foreach ( $value as $keyC => $valueC ) {
            $out .= "\n".$valueC;
        }

        $out .= '</script>';
    }

    //external script
    foreach ( $scripts_src as $value ) {
        $out .= '<script src="'.$value.'"></script>';
    }

    return $out;
}

Once done, edit your header.php file. Replace the wp_head() tag by this:

<?php
ob_start();
wp_head();
$themeHead = ob_get_contents();
ob_end_clean();
define( 'HEAD_CONTENT', $themeHead );

$allowedTags = '<style><link><meta><title>';
print theme_strip_tags_content( HEAD_CONTENT, $allowedTags );
?>

And finally, place the code below into your footer.php file, just before the closing </body> tag.

<?php theme_insert_js( HEAD_CONTENT ); ?>

Credit: Tomasz Dobrynski.

Only allow post author to reply to a comment on their post

If for some reason you only want to allow the post author to reply to comments, here’s a working solution. As often, you should add it to your theme’s functions.php file.

add_action( 'pre_comment_on_post', 'wpq_pre_commenting' );

function wpq_pre_commenting( $pid ) {
    $parent_id = filter_input( INPUT_POST, 'comment_parent', FILTER_SANITIZE_NUMBER_INT );
    $post = get_post( $pid );
    $cuid = get_current_user_id();

    if( ! is_null( $post ) && $post->post_author == $cuid && 0 == $parent_id ) {
        wp_die(	'Sorry, only post author can reply to a comment!' );
    }
} 

Source: GitHub

Display last modified date of a post

When you update your existing posts frequently, it is often more relevant to display the date of modification rather than the publishing date. Just paste this code where you want the date to be displayed. The function needs to be used within the loop.

<p>Last modified: <?php the_modified_date(); ?></p>

Source: WordPress Codex

Add Theme Editor shortcut to admin bar

If you often make modifications to your theme by using the built-in editor, it can be handy to add a shortcut to WordPress’ admin bar. Simply paste the code below in your functions.php file to proceed.

function admin_bar_theme_editor_option() {
    global $wp_admin_bar;
        if ( !is_super_admin() || !is_admin_bar_showing() )
        return;
        $wp_admin_bar->add_menu(
            array( 'id' => 'edit-theme',
            'title' => __('Edit Theme'),
                        'href' => admin_url( 'theme-editor.php')
        )
        );
    }
 
add_action( 'admin_bar_menu', 'admin_bar_theme_editor_option', 100 );

Source: WP Snippet

Schedule cron jobs with WordPress

Cron is a time-based job scheduler in Unix-like computer operating systems. It can be used within WordPress to schedule events, for example emptying your spam comment queue.
Here’s a basic code snippet to paste in your functions.php file, that will allow you to create a scheduled event.

<?php
add_action('my_hourly_event', 'do_this_hourly');

function my_activation() {
	if ( !wp_next_scheduled( 'my_hourly_event' ) ) {
		wp_schedule_event(time(), 'hourly', 'my_hourly_event');
	}
}
add_action('wp', 'my_activation');

function do_this_hourly() {
	// do something every hour
}
?>

Source: WP Snippets

Display a disclaimer on older posts

If you blog about technology, some articles that may have been useful 5 years ago can be completely outdated today. If a post is very old, it can be a good thing to warn your readers about it so they’ll know that the information they’re reading might be out of date.

Paste the following code in your single.php file, within the loop. Edit the sentence on line 7 as desired.

<?
$ageunix = get_the_time('U');
$days_old_in_seconds = ((time() - $ageunix));
$days_old = (($days_old_in_seconds/86400));

if ($days_old > 365) {
  echo '<div class="disclaimer">DISCLAIMER: this post is older than one year and may not be up to date with the latest WordPress version.</div>'; 
} 
?>

Source: CatsWhoCode

Slow load times: The Ecommerce killer

Consider this common scenario: A prospective customer opens their favorite search engine and inputs their search query, something like “adorable cake toppers.” The search returns over one million results. Our consumer opens about a half dozen pages – yours included. Clicking through each of the tabs, the shopper impatiently glances at photos and web pages, closing the windows that haven’t loaded along the way – yours included.

Research shows 40 percent of people abandon a website if it takes more than three seconds to load. Winning a sale or losing a customer comes down to a matter of seconds. Further, customers are prone to demonstrating weak confidence in your brand, if they consistently experience lethargy at your site.
Long story short, slow load times can be a real nightmare for ecommerce stores.

Block the Bots

One of the biggest instigators of slow load times is artificially bloated web traffic. In addition to being populated by people, the web also hosts bots. These are autonomous programs that interact with sites and services, often in a nefarious way.

Bots could be plaguing your ecommerce site without you even knowing it. They click advertisements, scrape content and weigh down your site, sometimes preventing real customers from interacting with your content.

This is obviously a problem, but an even bigger issue is Distributed Denial-of-Service (DDoS) attacks, which flood a website with phony web requests at the behest of a hacker until it crashes.

Thankfully, there are dozens of bot mitigation techniques. These include algorithms capable of detection and redirection of bogus traffic. You can also require CAPTCHA confirmations and block malicious bots.

Prevent “Scale Fail”

Excessive legitimate traffic can also buckle your operations. Every year, online stores (big and small) crash during Black Friday and Cyber Monday sales because they cannot handle the volume of incoming web requests.

This is a bit of a blessing and a curse. Customers are more than eager to visit your ecommerce site and spend money, but they will lose interest if they can’t get it to load. So how do you prevent this?

Free ecommerce website templates like those from Shopify offer pre-fab themes for quick site building along with a robust backend platform to handle heavy customer traffic. Stress testing in another good idea for e-stores that are unsure how durable their site is.

However, if you want to get creative, you could also parcel out specific sales over several days to avert “scale fail” during the busy season. For example, you could offer deep discounts on women’s clothing for Black Friday and a flash sale on men’s wear on Cyber Monday.

Build a Better Site

Similarly, there may be some site building tips of which you are not aware. For instance, did you know you could compress HD images for faster load times? This can make a big difference for sites with lots of product photos.

Another recommendation is to cut third-party advertising from your website. Banner ads and pop-ups do more to distract customers and slow load times than they do to drive sales or generate revenue.

Finally, use a website builder or platform compatible with smartphones and tablets. Mobile makes up 30 percent of all U.S. ecommerce, meaning it is absolutely vital to ensure your site is fast across all devices. Slow load times are an ecommerce killer, do everything you can to avoid falling victim to them.

This is a guest post by Susan Smith.

5 Web development languages you should learn

These days it can be difficult for even programmers with a formal education to get hired, especially if they aren’t well acquainted with the following languages. When you take the time to familiarize yourself with these languages, you will significantly increase your chances of getting hired after graduation. You can also do freelance work after you have gained this knowledge.

HTML5

There is no question that HTML5 is one of the most important programming languages that you can learn if you are planning on going into this line of work. If you want to become a web developer, you will find that it is essential that you familiarize yourself with this language as soon as possible. This is a scripting language and not a programming language itself, but you should definitely make a point of learning it.

If you aren’t very familiar with HTML5, you shouldn’t expect to get very far in this industry as a professional. There are still a lot of people who think that learning this language isn’t necessary at all, but it really is.

JavaScript

Through JavaScript’s frameworks and recent additions, it has turned into something that goes far beyond just outputting alert statements on a browser. It is important to keep in mind that this programming language combines very well with other web development languages, so it is no surprise that it’s still being used by many professionals today. If you really want to become a successful programmer, you will absolutely need to make a point of learning this language as soon as possible.

JavaScript is without a doubt one of the more popular programming languages today, though it has been around for quite a while now. Lots of tech companies consider knowledge of JavaScript essential for new hires, so you will need to keep this in mind. A JavaScript developer can easily make big money, and there is a lot of demand for those who are very knowledgeable. There are 3 billion phones that run Java, as well as 125 million TV devices and a 90% of all computers in the U.S.

PHP

PHP is yet another incredibly important programming language that you will simply have to learn if you want to work in this industry. It is responsible for powering many websites, and it goes hand-in-hand with HTML. Magento, which is the world’s most popular eCommerce platform, is run on PHP. Magento is written in PHP, which really says something about the utility of this programming language with regards to web development.

If you favour PHP as a programmer, you will definitely want to look into finding a PHP host in particular. These hosts will allow you to run your website smoother than you ever thought possible. While it’s true that you can choose just about any host, a PHP provider is a particularly good choice. In the end you will find that this provider will make keeping your website up and running at all times much simpler and less problematic. A vast majority of web hosts are not set up to accommodate PHP users in particular.

Python

Python is one programming language that you absolutely must learn if you want to go into this line of work. It is a wonderful general-purpose, high-level programming language with an emphasis on code readability. This is also one of the easier programming languages to learn, which is why many people start off with it when learning how to code. Its common words and expressions as well as more white space and fewer curly brackets make it an excellent choice if you are an aspiring programmer.

Right now there are a lot of different companies that are looking for people who are very familiar with Python. This means that learning the ins and outs of this programming language will most likely earn you a leg up in the job market. These days people need all the credentials they can get to find a job, and this is definitely a good one for a computer programmer. Companies that are looking for full stack developers usually list Python as a required language for new employees.

Whilst it is possible to code Python locally, it might be best to find a web hosting company who specifically offer support for Python based applications via frameworks such as Django as this will make building your application so much easier.

SQL

SQL, which is actually pronounced “sequel,” stands for Structured Query Language, and it is a special-purpose programming language that is primarily used for getting information from and updating databases. Nearly all businesses run a database system of some kind, so SQL is a great skill to list on your resume. If you want to increase your chances of getting hired right out of college, you will certainly need to make a point of getting intimately familiar with this particular programming language.

If you become an expert in SQL, you could get a job as an SQL Database Manager, SQL Developer and SQL analyst, though a lot of general data analyst jobs will also require knowledge of this language. You will find that it is widely used across database applications as well as web frameworks.

Final thoughts

The more time and effort you invest into learning programming languages, the better of a chance you will have of getting hired into your dream job after you graduate. These days it is more important than ever to possess a versatile knowledge of computer programming languages. Those who do not possess a working knowledge of all these languages will most likely find it difficult to get hired anywhere as a computer programmer. There are some languages that are more important than others for certain jobs, but all of the ones listed in this article are crucial pretty much across the board. As long as you make a real effort to familiarize yourself with these languages, you shouldn’t find it difficult to get a job in this industry.

This is a guest post by Moeez Ali.

Fatal blunders to avoid when choosing a web hosting company

That is why experts of ukessaynow.com believe in getting it right since having a good website without a good host will be tantamount to serving your visitors their best meal on a broken and stinking plate. Therefore, we present you with the most terrible mistakes that will hurt your selection of a web-hosting company.

Failing to consider the safety of your money

Unless you are going for free hosting, be mindful of the safety of your money. The reason is that even the best performing companies offer their users a guarantee for their money in the form of refunds. Before settling for that company, it is necessary to ascertain that the company has your best interests at heart by offering unconditional refund without taking you through a million “terms and conditions.” Therefore, even if the company claims to offer a money-back guarantee, you need to be careful and read through the details to know the ease with which you can get your money back. To be on the safe side, just read the details carefully.

Failing to define your hosting needs

Another mistake some site owners make is jumping into the contract without sitting to define the finer details of their hosting needs at the time of launching and the foreseeable future. The reason is that you can underestimate your needs and go for a shared or free hosting package since your website is small. But since things can blow out of your control and end up needing your own space, you may end up locked in a deal that is not serving your needs. Therefore, it is necessary to take time and analyze your needs so that you do not get the wrong package. You should also look at the kind of features you value in a hosting package before settling for a particular company. For instance, if you want to enjoy higher domain safety such as SSL certificate installation, email support, and higher privacy, it will be prudent to go for a business class self-hosting.

Using price as the sole determinant

The third mistake that many users make is looking at the hosting package based on the quantity of money they can pay as opposed to the quality of service they will enjoy. That is why you need to bargain the deal based on your needs and what you want to achieve without making money the primary determining factor.

Ignoring potential security issues

If you want to enjoy better operations on the Net, do not forget your need for security. As a wise buyer, you need to consider the safety of your website and your information as well as that of your users. For instance, if you are going to accept payments on your site or receive sensitive user details such as bank and credit card information, ensure that it is secure enough to facilitate this level of transaction. Therefore, it is essential to consider the ability to install an SSL certificate to boost your users’ security.

Going for free packages

Even though there is nothing essentially wrong with using free hosting, you need to be careful how you approach such offers. If you don’t want any of the following experiences on your website, then avoid them:

  • Low loading speeds owing to many shared “tenants” on the server
  • Unsolicited third-party adverts on your website
  • Inability to run particular scripts
  • Inability to scale your website as it expands

Failing to listen to what other users are saying

User reviews are instrumental in assessing the suitability of any online hosting details. Therefore, you need to take your time to read the reviews users are making about the company. You should pay particular attention to how they handle customer complaints, deal with security challenges, and address slow loading speeds. You should also check if the company receives 100 percent positive reviews since such a move is a pointer that the reviews are doctored.

Failing to pay attention to restrictions

Lastly, you need to pay attention to limitations and restrictions that your hosting company will impose on your online tenancy. For instance, you should be wary of promises as such as “unlimited” bandwidth since such a promise may entail a limitation of other features that you may find necessary for your smooth operations. Most of them usually reduce your speed when you reach a certain level of consumption. Additionally, you need to find out if they will allow you to install your own software on the site, if they allow SSH, and the company permits users to have several POP accounts.

With all these mistakes at your fingertips, we believe you will be in a better position to make a profitable decision that will give you value for your money. The ball is now in your court to avoid these blunders and choose the best host for your new website.

This is a guest post by Svetlana Zamkovaya.

The website checklist: 14 vital points for a quality website

SEO

SEO stands for “search engine optimization.” It is the process of getting traffic from the “free,” “organic,” “editorial” or “natural” search results on search engines.

Let’s take a look at a few optimizations you can make to help your website rank higher in search engines’ results pages.

Your website is using pretty URLs

Nowadays, almost every website is using pretty URLs which include descriptive keywords of the page content. If your website doesn’t use them yet, it’s time to get your hands dirty. This handy guide can help if you’re new with URL rewriting.

Your images has proper alt attributes

The alt attribute is quite often neglected by developers and websites owners – even though it plays a role in SEO and also makes your website more accessible, for example in the case of people using a text-based browser.

Your site is using a sitemap

A sitemap is, as the name tells, a map of your site. It’s used to tell search engines which URLs it should index. Sitemaps can be generated easily using this generator. WordPress users have plenty of choice of plugins that will generate a sitemap.

Your website is using HTTPS/SSL

Google loves HTTPS websites, because they’re offering a way more secure experience to users than the HTTP protocol. Therefore, secure websites tend to rank higher than HTTP ones. Check my HTTPS guide if you need help in installing HTTPS on your site.

Your <title> tag is optimized

Located in the <head> part of a HTML document, the <title> tag is extremely important since it is displayed by most search engines in their result pages. Make sure your title is describing your page content accurately and contains keywords.

Your website is using OpenGraph

The Open Graph protocol enables any web page to become a rich object in a social graph. For instance, this is used on Facebook to allow any web page to have the same functionality as any other object on Facebook.
To turn your web pages into graph objects, you need to add basic metadata to your page, which is explained in details here.

Speed Optimization

A quality website is a fast website. Speed optimization is extremely important, since over half of your visitors are accessing your site through mobile devices. Also, a faster website will rank higher in search engines. Let’s browse what can be done to improve your website loading speed optimization.

Your images are optimized

Images represent over 60% of the average byte per content type downloaded when a web page is loaded. This is why it’s extremely important that your images are optimized if you want your website to be fast. Check out my image optimization guide for more info.

Your CSS and JS files are minified and combined

Minifying CSS/JS means removing comments, line breaks and all the other stuff which isn’t needed for your site to function properly. Combining is the action of grouping multiple files into one, and therefore making your site faster by limiting HTTP requests.
On WordPress, I recommend using the W3 Total Cache plugin for this purpose. You can also manually minify/combine your files using this tool.

Your server is fast

According to Google, you should reduce your server response time under 200ms. A great tool to check your server speed is Pingdom. I recommend Vidahost, Dreamhost, WP Engine and SiteGround as fast hosts. If you’re using WordPress, using a speed-optimized WordPress theme can definitely help making your site faster as a whole.

If you need more info about fast webhosts for WordPress, here are lists of the best managed WordPress hosting and the best WordPress hosting.

Gzip compression is activated

Check if Gzip compression is enabled on your website. If it’s not, here’s a simple tutorial on how to activate it on various webservers.

Leverage browser caching

“Leveraging” browser caching is when a webmaster has instructed browsers how their resources should be dealt with.
Here is an extensive article about the technique and how to apply it to your own website.
If you’re looking to add expire headers to external files (Like Google Analytics’ .js file, for example) you can turn to this guide I wrote a while ago.

Website Security

At last but not least, let’s review what should be done on a website to ensure proper security. Although not extensive, this list is a good start.

Your scripts are up to date

If you’re using WordPress, Magento, Prestashop or any other script/CMS, it’s vital that you keep them, as well as their dependencies, up to date.

Directory listing is disabled

By default, most web servers are allowing visitors to browse the content of a directory, which can lead to potential vulnerabilities. To protect your site, you can either upload a blank index.html file in every directory that needs to be protected against directory listing, or you can paste the following into your .htaccess file if you’re using Apache:

Options -Indexes 

Your site is protected against SQL injections

SQL injections are one of the most common attacks towards a website. Basically, a SQL injection is an attack wherein an attacker can execute malicious SQL statements that control a web application’s database server.

In case you are new to web development, there are many online resources that can help you to learn how SQL injections work and how you can protect your website from it. Alternatively, you can hire a professional. This site, for example, offers Cyber Security Jobs in the UK.

Any other tip we should include in the list? Let me know in a comment below.

How To Change The Default WordPress Media Uploads Folder

This disappointed many bloggers. Mostly because using a custom media uploads directory made it easier to browse media files in one place rather than having to browse in multiple folders by month and year. It also had a small SEO benefit, especially when you host multimedia files such as PDFs.

Luckily, there is a way you can get around this problem and customize the default media uploads path of your website. Here’s how you can do it.

Note: Following strategies involve customizing your website’s core files and editing code. Make sure to fully backup your website and files before trying out any of these methods.

Method #1 – Use A Plugin

The easiest way to change the default media uploads path is to use the WP Original Media Path plugin.

Once installed, this plugin will allow you to easily change the default media directory into any path you like.

For example, your current media uploads path may look like this: http://yourdomain.com/wp-content/uploads. You can customize it to a more professional path like http://yourdomain.com/media using this plugin.

Keep in mind that this plugin will only change the uploads folder for your future uploads. You’ll have to manually move the media files to the new folder if you want them to appear in the new and updated media path.

If you decided to move the media files, you can then use the Search & Replace plugin to modify MySQL to make sure your previously published articles find the media files from the new uploads folder.

Method #2 – Customize WP-Config.php

The other method is also simple, but it involves editing a core WordPress file.

First, access the root directory of your WordPress installation using the File Explorer in your web hosting CPanel or using an FTP client. Then find a file named wp-config.php and open the file to edit.

Then add the following line in the wp-config file:

define( ‘UPLOADS’, ‘wp-content/’.’media’ );

This will make all your media uploads go in a folder named “media”. But it will still be inside the “wp-content” folder.

If you want the uploads to go in a direct folder, like yourdomain.com/media, then use the following code instead:

define( ‘UPLOADS’, ”.’media’ );

Also, make sure to add the following code right before the line as well:

require_once(ABSPATH.’wp-settings.php’);

This will automatically create a folder in the WordPress directly if it doesn’t exist. Or, you can manually create the folder in the right path using the FTP client.

The post How To Change The Default WordPress Media Uploads Folder appeared first on WPRecipes.

How To Change The Default WordPress Media Uploads Folder

This disappointed many bloggers. Mostly because using a custom media uploads directory made it easier to browse media files in one place rather than having to browse in multiple folders by month and year. It also had a small SEO benefit, especially when you host multimedia files such as PDFs.

Luckily, there is a way you can get around this problem and customize the default media uploads path of your website. Here’s how you can do it.

Note: Following strategies involve customizing your website’s core files and editing code. Make sure to fully backup your website and files before trying out any of these methods.

Method #1 – Use A Plugin

The easiest way to change the default media uploads path is to use the WP Original Media Path plugin.

Once installed, this plugin will allow you to easily change the default media directory into any path you like.

For example, your current media uploads path may look like this: http://yourdomain.com/wp-content/uploads. You can customize it to a more professional path like http://yourdomain.com/media using this plugin.

Keep in mind that this plugin will only change the uploads folder for your future uploads. You’ll have to manually move the media files to the new folder if you want them to appear in the new and updated media path.

If you decided to move the media files, you can then use the Search & Replace plugin to modify MySQL to make sure your previously published articles find the media files from the new uploads folder.

Method #2 – Customize WP-Config.php

The other method is also simple, but it involves editing a core WordPress file.

First, access the root directory of your WordPress installation using the File Explorer in your web hosting CPanel or using an FTP client. Then find a file named wp-config.php and open the file to edit.

Then add the following line in the wp-config file:

define( ‘UPLOADS’, ‘wp-content/’.’media’ );

This will make all your media uploads go in a folder named “media”. But it will still be inside the “wp-content” folder.

If you want the uploads to go in a direct folder, like yourdomain.com/media, then use the following code instead:

define( ‘UPLOADS’, ”.’media’ );

Also, make sure to add the following code right before the line as well:

require_once(ABSPATH.’wp-settings.php’);

This will automatically create a folder in the WordPress directly if it doesn’t exist. Or, you can manually create the folder in the right path using the FTP client.

The post How To Change The Default WordPress Media Uploads Folder appeared first on WPRecipes.

Best universal VPNs for PC, Mac, phones & tablets

The second purpose of a VPN service is privacy. It helps if you want to protect your data from being looked at. Especially, if you are going to visit other countries, where the government is constantly following the Internet users.

There is a lot of VPN softwares on the market. Today, we’re going to talk about top 3 services, which suit PC, Mac, phones, and tablets as well. To get more detailed information, visit this compiled a list of VPN providers and make your device fully protected.

So, let’s get started.

Top 3 VPNs for Any Device

When searching for a good VPN service, the big thing to look for is how many devices a VPN service supports. Sometimes a VPN is quite good, has high speed, but it supports different devices separately for different prices. Thus, all devices together can be too expensive for an average user. We’ve prepared a list of top 3 VPN services you should definitely look at in 2017.

1. TunnelBear

This service offers one stable price per month or year, enabling you to connect 3 different devices at the same time: PC or Mac, tablet, and phone. Overall, it is a reliable company with quite reasonable prices – $9.99 per month or $4.99 per month for 1 year. As a bonus, you get 500 megabytes per month for free. So, you can install TunnelBear, play with it, look if it meets your requirements, and decide whether to continue using it or not.

2. ExpressVPN

This VPN service is one of the most popular ones among average internet users. Why? First, it is compatible with PC/Mac, phones, and tablets too. Secondly, the pricing policy is very flexible and user-friendly. ExpressVPN offers 3 types of packages, which have different types of savings on annual costs. 1 month – $12.95, 6 months – $12.99, and 12 months – $8.32. And the third reason is ultra fast servers in 90+ regions and 144+ cities (Canada, USA, Germany, Ukraine, Turkey, etc.).

3. IPVanish

The last VPN service we can recommend in 2017 is IPVanish. It has definitely became one of the biggest server bases, bigger than any other VPN on the market. The most interesting pro of this service is a huge list of available countries. If you are in a different country, nine times out of ten, that you are going to find an IPVanish server that fits your needs. Likely to the previous VPN services, this one is also compatible with 3 different devices: PC/Mac, phone, and tablet.

This is a guest post by Amélie Blanche.

weForms- a fast & easy WordPress form builder with cutting-edge performance

weForms comes from weDevs, the makers of WP User Frontend and here’s why you should try out weForms for your next form-building projects:

It has been crafted for the average and general user, making it so easy to use. It is super fast thanks to Vue.js framework. At the same time, weForms features important and advanced functionalities like productivity and email marketing integration.

weForms overview

I got a free copy of the Personal Pro version of weForms, but there is also a free version which covers all the basic essentials to set up a contact form on your website. This review will be covering firstly the features in general and then get into specifics about how to create a form. So that you can understand what makes it a good plugin for contemporary websites and businesses. weForms is a modern form-builder with several integrations that augment its functionality.

1. weforms

Some of its general features are:

  • One click activation
  • Super fast form creation
  • Live real-time preview
  • Built-in templates
  • Drag & drop builder

Though it’s designed to be user-friendly so that the average user can find creating forms a piece of cake, don’t feel it to be weak. The plugin works really fast and is simple to understand but it’s also very extensible. weForms is fully competent enough to accomplish advanced tasks.

  • Advanced Fields
  • Field customization
  • Conditional logic
  • Multistep form
  • Mobile-responsive
  • Export/Import forms
  • Image & file uploaders
  • Expiry time
  • Entry restrictions
  • Customizable email notifications
  • One page submission via AJAX
  • SMS notification
  • Customize mails
  • MailChimp, Paypal, Slack, and several other integrations

The intuitive interface that uses drag and drop and free built-in templates, ensures that you have it all that you need within you hands. weForms is also responsive so if you are ever in a rush, you can quickly create with your portable devices within a short time.

Installation & Basic Settings

Installing weForms was simple as ABC. As in the usual way for other plugins, you can install it from WordPress.org or download the Pro version and install it in the regular way.

2. weForms installation

Creating your first form

Coming to the most important part. I have already mentioned a lot on how less time-consuming and easy it is to build forms on weForms. And it’s time to illustrate it.

Clicking on the Add Form will open up the following screen below. Here you will notice 3 built-in templates for Contact Form, Support Form, and Event Registration Form.

3. weForms installation1

You can also choose to start with a custom/blank template.

As you will notice, weForms has done a lot to simplify the process with the predefined templates, which are also customizable.

The templates appear like this in default mode:

Contact form

4. weForms drag drop live builder

Support form

5. weForms support form template

Event registration

6. weForms event form templates

In case you choose to go for a blank template, this is how you create a new form using a blank template.

Form Settings

The form settings tab open up when you open a new form from the templates or custom.

7. weForms settings

Here you can choose from the drop-down to redirect your form to the same page as it gets submitted in, or to a different page or to a custom URL.

Want your forms to have a time and entry limit? You can easily do this through the Submission Restriction part where you can schedule your form, require a login from your users, and also restrict your entries to a certain number. The settings are easy as pie to set.

8. weForms settings schedule

9. weForms submission restrictions

Finally, you can also select how your labels should appear.

10. weForms display settings label position

With notifications, you can set up everything for email. It gives you complete control over where, from and to whom, email notifications will be sent including what to be sent.

11. weForms admin notifications email settings

weForms’ Fields

One of the most important part of the weForms’ builder is its live preview and drag & drop function. To begin, just drag and drop the fields you want in your form. Reorder them as you like. As you make changes, the dynamic builder will change accordingly as you go on about editing. This gives you an automatic preview of what the form will eventually look like to your users. The process lives up to the promise of being user friendly.

12. weForms custom CSS

You can also customize each field as you desire with custom CSS. Being able to customize means that tweeking your fields a little can change the overall look of your form for the better. You can match it to your website or highlight specific elements. The weForms fields are:

  • Name
  • Text
  • Text area
  • Dropdown
  • Multi-select
  • Radio
  • Checkbox
  • URL
  • Email Address
  • Hidden field
  • Image upload
  • Repeat field
  • Date/Time
  • File upload
  • Country list
  • Numeric field
  • Address field
  • Step Start
  • Google map
  • Section break
  • Custom HTML
  • reCaptcha
  • Shortcode
  • Terms & conditions
  • Action hook
  • Ratings

Publishing forms

The process of publishing a form and making it live is simple. Like most other plugins, simply copy the shortcode present at the top of the form by clicking on it. You can now post this on a new page or in your posts.

13. weForms shortcode

Here’s a sample. With weForms, you get a clean look from the frontend.

14. weForms frontend view

Managing submissions

Viewing and managing responses is extremely easy. Simply navigate to weForms ? Contact Forms. You can view each of the detailed responses by clicking on each response.

15. weForms full entry details

Want to export your forms to other solutions? You can do this in the form of an organized spreadsheet which comes built-in into the system.

16. weForms manage entries

Add-ons

The Personal Pro Plan includes the following add-ons and comes integrated with weForms:

  • MailChimp
  • MailPoet
  • Slack
  • AWeber
  • Zapier
  • Constant Contact
  • ConvertKit
  • Hubspot
  • Campaign Monitor
  • GetResponse
  • Google Sheets

Grand Giveaway

weForms comes in 4 pricing plans in addition to the free version. The plans are Personal, Professional, Business, and Developer. With the Developer plan being the most advanced in features. weForms is currently offering its Personal License for free for 3 months.

The regular Personal plan is priced at $39. So it’s a great opportunity for you to learn about this new addition to the form-builder market with its advanced features.

17. weForms install pro for free

I am not recommending just because it’s free, but because I have found out it has many exciting features. Most importantly, it is extremely fast and everything loads on a single page. Sometimes great things come for free too. And having personally used it, I can vouch for its performance in terms of ease and quickness.

Final words

Overall, I felt positive about the weForms plugin. It does what it says. As far as creating a fast and easy to use form builder is concerned, I feel they have definitely achieved it so far with all the essentials.

So in conclusion: if you are looking for an easy to understand and easy to use plugin for your business or website that gives you very modern functionalities and outlook, both basic and advanced, weForms is a great choice. And because the Pro version is now available for free for 3 months, it’s a chance that should not be missed to dig deeper into weForms.

Pros

  1. Super fast & very easy to use
  2. Awesome live preview & drag and drops
  3. Personal license is being given away for free
  4. FREE slack integration
  5. You can also import forms from other plugins as well

Cons

Didn’t find any yet!

This is a guest post by Rounak Ahmed.

10 useful text formatting tools for web developers and online publishers

Txt Format

This website aims to help you with tasks where text formatting is needed. It’s not intended to replace a word processor, but the formatting tools available there can help speed up some jobs which might otherwise be long and repetitive.

Website: http://txtformat.com/

XML Formatter

Formats a XML string/file with your desired indentation level. The formatting rules are not configurable but it uses a per-element indentation pattern giving the best readability.

Website: https://www.freeformatter.com/xml-formatter.html

Remove line breaks

If you’ve ever received a text that was formatted in a skinny column with line breaks at the end of each line, like text from an email or copy-pasted text from a PDF column with spacing, word wrap, or line break problems, then this tool is pretty darn handy.

Website: https://www.textfixer.com/tools/remove-line-breaks.php

Word to HTML

We all know a colleague or a client that keeps sending Microsoft Word files containing articles to publish or even HTML. While Word is a good text processor, its internal markup can quickly becomes a nightmare if you copy-paste it into a CMS or HTML file. Here’s a pretty good tool to get rid of most Word markup.
Website: https://wordtohtml.net/

CSS Beautifier

Enter your messy, minified, or obfuscated CSS Style Sheets into the field to have it cleaned up and made pretty. The editor also contains helpful line numbers and syntax highlighting. There are many options to tailor the beautifier to your personal formatting tastes.

Website: http://www.cleancss.com/css-beautify/

CSS Minifier

The counterpart of CSS Beautifier: This super useful tool allows you to minify (removes the spacing, indentation, newlines, and comments) a CSS file online in order to optimize your website speed.
Website: http://www.cleancss.com/css-minify/

HTML Formatter

HTML Formatter is a free online tool to format an ugly HTML code, making it readable and pretty, with the proper indentation. Very handy on a daily basis.

Website: http://htmlformatter.com/

Strip HTML

Strip HTML gives you a quick, easy and satisfying way to transform your ugly formatted and/or HTMLified text into a clean and pretty text for you to enjoy.

Very useful when needing to get text from a HTML source.
Website: http://www.striphtml.com/

PHP Beautifier

Proper formatting makes code easier to read and understand. PHP Beautifier parses your source code and formats it in the style of your choice. As a developer often working with messy code from custom WordPress Themes, this is a tool I basically can’t live with.
Website: http://phpbeautifier.com/

Find and Replace Text

A pretty good tool for searching and replacing occurences in a text file. The tool supports case-matching searches as well as Regular Expressions.
Website: http://textmechanic.com/text-tools/basic-text-tools/find-and-replace-text/

Any other text formatting tool we should recommend? Let us know in a comment.

Hostinger giveaway: Win one year of hosting and a free domain name

About Hostinger

Hostinger is a leading worldwide cheap web hosting provider for millions of smart people, who really love to save a lot without losing high-quality & premium webhosting features.

Established over 10 years ago in Europe, Hostinger main goal is to provide quality hosting at a price accessible to everyone. Their popular “Business Plan” offers PHP 7.1 support, unlimited sites/SSD disk space/bandwidth, daily backups and a free SSL certificate. For more info about the plan’s features and a comparison to popular webhosts HostGator and BlueHost, just have a look over there.

Another very interesting plan from Hostinger is the “Single Web Hosting” plan. Billed $2.15 a month, this extremely cheap plan is designed to host a single, low traffic website. Of course, don’t think about hosting a popular site on that plan, but if you want to have a demo for a WordPress theme, or just a very simple site, this is truly one of the cheapest options ever.

And last but not least – Hostinger is 100% WordPress ready and offer a simple one click installation for our favorite CMS/blogging platform. And if you need help on installing WordPress, they have a handy, step by step tutorial to help you out.

How to enter the giveaway

Feeling lucky? Today CatsWhoCode is offering you the chance to win one year of hosting from Hostinger, as well as a free domain name, under the terms of Hostinger’s Premium Hosting Plan.

In order to take part in the giveaway, just leave a comment below to let me know you’re in. In one week (September 18, 2017), the winner will be randomly chosen and will receive his prize directly from the Hostinger team.

Good luck!

3 Different ways to build your first website

1. Launch Your Site With Website Builders

Website builders are a type of online software provided by hosting companies that allow you to create and publish a website without manual coding. These include companies like Wix, Weebly, SiteBuilder, SquareSpace, and Webs.

Website Builder Pros

Website builders are great for beginners thanks to their user-friendly interfaces. Most feature page templates and drag-and-drop editors that make it simple for anyone to set up a website.

Not only that, but many website builders like Wix are free, with upgrades available for just a few dollars per month if you need additional features.

Website Builder Cons

Although website builders are user-friendly and cheap, they come with their limitations. For one, without access to your website’s code, customization options are limited.

With many free packages, you’re limited on the number of pages you can have, how much storage space you’re provided, and what domain name you can choose. In many cases, the website host reserves the right to display advertisements unless you upgrade your plan.

Bottom Line

Website builders are best for beginners on a budget who are wanting to set up small personal websites. Website builders can also work for small businesses depending on their needs.

2. Use a Content Management System

A content management system (CMS) is a type of software like WordPress, Joomla, or Drupal that allows you to create and control digital content. Though there’s a bit of learning curve, they are more versatile than website builders.

WordPress is the most popular content management system, powering over a quarter of the Web. Though you can get started for free at WordPress.com, your best option is to go the self-hosted route and download the full version of the CMS at WordPress.org. The software is still free, but you’ll have to pay for hosting through a company like Bluehost or Hostgator. (You can also host your website on your own servers, but this is rare.)

Once you’ve set up your website through your host, install the CMS software onto your site. Luckily, most hosts like those mentioned above offer one-click installs to make the process completely hassle-free. Your host will email you when the install is complete. Then, simply log in to your website and begin building it!

CMS Pros

With a CMS like WordPress, you’ll have access to thousands of templates or can upload your own. You can also install third-party plugins, which expand the functions of your site, as well as access your website’s code for full-range customization.

The software can power the smallest of personal websites to large corporate websites. In fact, many big brands like Tech Crunch, Time, and The Wall Street Journal are powered by WordPress.

WordPress can accommodate blogs, portfolio sites, eCommerce websites, forums, booking sites, coupon websites, and much more. Plus, it comes with the tools to make your site mobile-friendly and easily discoverable by search engines. Basically, your only limitations are in your hosting provider.

CMS Cons

It helps to have a bit of technical knowledge when using content management systems, but with how popular these platforms are, it’s pretty easy to find help around the Web.

Also keep in mind that security is an important concern, especially with a platform as popular as WordPress.

Bottom Line

Content management systems are a great choice for most people, and though they come with a bit of a learning curve, there are plenty of resources available online. However, they aren’t for everyone; large corporations, social networking sites, and large eCommerce operations may find that going the complete custom route is better for them.

3. Build Your Site From Scratch

A final option for building your website is starting from scratch. You can do this by designing your site through HTML, which is a globally recognized programming language that controls your site’s formatting and content.

If you’re willing to learn, you can set up your own HTML website; otherwise, you can hire a designer or design company to do it for you. They might use a combination of HTML, JavaScript, CSS, template design software like Dreamweaver, and more.

Building From Scratch Pros

Building your site from scratch with HTML is a good option for static websites. It allows for complete customization on the appearance and layout of the site, and assuming you don’t plan to change your content often, there’s little to no maintenance required.

Plus, these websites tend to be more secure than those built with website builders or content management systems.

Building From Scratch Cons

Building a site from scratch comes with a huge learning curve and can be difficult to manage if you’re not sure what you’re doing.

If you want to hire a web developer to handle the customizations for you, it can get quite costly. Plus, you give up some of your control because you’ll have to get in touch with your web developer when you want to make changes.
HTML isn’t the best option for dynamic websites where the content is constantly changing.

Bottom Line

Unless you’re a web developer yourself or a large company willing to hire out the task, there’s really no reason you need to go the completely custom route.

With all these choices, it can be tough to decide which option is right for you, but it all comes down to your needs, budget, and skill level. If you’re an individual on a tight budget, start with a website builder. If you’re a bit more tech-savvy, willing to put in a bit more money, and need additional functionality, go with a CMS. If you’re a web developer or a large company with the means to invest in a completely custom design, consider starting from scratch.

This is a guest post by Robert Menning.

Zyma.com giveaway: 500£ worth of SSD hosting to win!

About Zyma Web Hosting

Zyma is a UK based web hosting company. It started in 2010 in the bedroom of a computer science student with a vision to make a web hosting company that cares highly about giving the best customer service. Since then, Zyma has gained customers in over 65 different countries covering four different continents.

As a small, human-sized company, Zyma focuses on quality and aims to provide every single customer with professional service and tools that will ensure their websites run smoothly, fast, and with a 99% guaranteed uptime.

What’s to win?

Now that I’ve quickly introduced Zyma to you, let’s have a closer look at what the company is offering to 5 of our lucky readers.

Prizes are 5x Business Plan Hosting. This hosting plan contains SSD hosting and a CDN to ensure a speed optimized website, unlimited emails, and a SSL certificate for having your site running on HTTPS. And if you’re using WordPress, no worries – the plan is completely compatible with the popular CMS.

Detailed specs:

  • 10GB SSD Storage
  • Unlimited Email Accounts
  • Free SSL Certificate
  • Host up to 5 Websites
  • Free Website Migration
  • SSD Hosting with cPanel support
  • Free Cloudflare CDN service
  • Free 365 day Technical Support
  • 250+ scripts supported, including WordPress, Moodle, Magento and many more!

How to enter the giveaway

Joining our giveaway is super simple and 100% free: Just use the Rafflecopter box below to enter. The giveaway will run for one week starting from today (September 05, 2017). Winners will get their prizes directly from the Zyma staff.

Good luck everybody!

a Rafflecopter giveaway

Themefuse giveaway: 5 lifetime packs to win!

What’s to win

In order to have a chance at one or more of these gifts, complete as many tasks from the list below as you want.

Each task awards a number of points – the more you get, the higher your chances to win. Based on this number of points, you’ll also have a chance at the Secret Prize.

Nobody leaves empty-handed though; no matter the results, you’ll automatically get the ebook “WordPress website launch 101. All you should know when launching a new website with WordPress”.

To enter the competition, the only requirement is that you are over 18 years old. The winners are announced in a week so make sure you keep an eye on Themefuse.com and this CatsWhoCode post!

Here are the gifts packs:

  • 1st Place – 1 lifetime pack from ThemeFuse + 1 website SEO audit from Seolitte + 1 Secret Prize
  • 2nd Place – 1 lifetime pack from ThemeFuse + 1 website SEO audit from Seolitte
  • 3rd Place – 1 lifetime pack from ThemeFuse + 1 website SEO audit from Seolitte
  • 4th Place – 1 lifetime pack from ThemeFuse
  • 5th Place – 1 lifetime pack from ThemeFuse

How to enter the giveaway?

Joining the giveaway is free and easy. The only requirement is that you are over 18 years old. Just use the Rafflecopter box below. The giveaway will run for one week starting from today (August 30, 2017). Winners will get their prizes directly from the Themefuse staff.

Good luck everybody!

a Rafflecopter giveaway

How to automatically add pretty messages on your WordPress blog

Downloading and inserting FontAwesome

The first thing you need to do is to download FontAwesome, since we’ll use it for our icons.

Once you’ve downloaded FontAwesome, include it in the head tag of your header.php file:

<link rel="stylesheet" href="path/to/font-awesome/css/font-awesome.min.css">

The CSS

Let’s continue by adding the necessary CSS classes. Open your theme’s style.css file and append the following to it:

.box{
	background: #E4F0FC;
	margin: 1em 0px 1.5em;
	padding: 12px 10px 12px 15px;
	color: #555;
	text-shadow: none;
	font-weight: bold;
}

.box i.fa{
	background: #5999cf;
	color:#fff;
	padding:7px 10px 8px 11px;
	border-radius:50%;
}

.box a{ color:#5999cf !important}

.box.red{ background: #FFD9C8; }
.box.red a{ color:#E97373 !important}
.box.red i.fa{ background: #E97373; }

.box.green{ background: #edfcd5}
.box.green a{ color:#80b42b !important}
.box.green i.fa{ background: #80b42b; }

Pretty self-explanatory, the first class defines the message box, and the two others allow you to change the box color from its default blue to red and green respectively. Please note that you might need to adjust the padding on .box i.fa because FontAwesome icons might have different sizes.

Add custom content after each single post

Many blogs are automatically displaying a message after the post content. It can be used to display related posts, author info, or like in the example below, to suggest considering a Bitcoin donation.

This code goes in your theme’s functions.php file.

function cwc_aftersinglepost( $content ) {    
    if( is_single() ) {
		$message = '<div class="box"><i class="fa fa-btc" aria-hidden="true"></i>Enjoyed this article? Please consider donating: <a href="bitcoin:3FVR5qaxYV8yAgNUUS7FC3o8c54YfDR5zK">3FVR5qaxYV8yAgNUUS7FC3o8c54YfDR5zK</a></div>';
        $content .= $message;
    }
    return $content;
}
add_filter( 'the_content', 'cwc_aftersinglepost' );

The result will look like this:

Enjoyed this article? Please consider donating: 3FVR5qaxYV8yAgNUUS7FC3o8c54YfDR5zK

Add custom content before each single post

Now that we saw how to automatically add content after a post, it’s super easy to adapt the code to display a custom message before the post as well.

Paste the following code into your functions.php file:

function cwc_beforesinglepost( $content ) {    
    if( is_single() ) {
		$custom_content = '<div class="box green"><i class="fa fa-info" aria-hidden="true"></i> Display some info here.</div>';
		$custom_content .= $content;
	}
    return $custom_content;
}
add_filter( 'the_content', 'cwc_beforesinglepost' );

It will look like this:

Display some info here.

Add a warning after each single post that is older than 2 years

If you started blogging a long time ago, there’s most probably some content on your blog which is now a bit out of date with the latest technologies.

For that reason, it’s a good thing to warn your readers about it. Using the is_old_post() function created by the folks at WP Engineer, it’s really simple to take one of the examples above and modify it a bit to fit this need.

function is_old_post($days = 5) {
	$days = (int) $days;
	$offset = $days*60*60*24;
	if ( get_post_time() < date('U') - $offset )
		return true;
	
	return false;
}

function cwc_oldpostwarning( $content ) {    
    if( is_single() && is_old_post(730) ) {
		$custom_content = '<div class="box red"><i class="fa fa-exclamation-triangle" aria-hidden="true"></i> Warning: This article is over 2 years old and might not be up to date.</div>';
		$custom_content .= $content;
	}
    return $custom_content;
}
add_filter( 'the_content', 'cwc_oldpostwarning' );

Result:

Warning: This article is over 2 years old and might not be up to date.

Creating a shortcode for custom messages

This article wouldn’t be complete without a solution to easily display custom messages within your blog posts or pages. To do so, let’s create a shortcode.

Simply paste the code below into the functions.php file from your theme:

function cwc_message( $atts, $content = null ) {
    return '<div class="box"><i class="fa fa-info" aria-hidden="true"></i> '.$content.'</div>';
}
add_shortcode('message', 'cwc_message');

Once saved you can easily insert custom messages in posts by using the shortcode we just created:

[message]Test[/message]

The result:

Test

That’s all for today – Have fun experimenting with the message boxes!