PHP Archives - SecondLineThemes Premium WordPress Themes & Development Tue, 25 May 2021 12:09:36 +0000 en-US hourly 1 https://secondlinethemes.com/wp-content/uploads/2020/09/cropped-icon-32x32.png PHP Archives - SecondLineThemes 32 32 Fix “Parse error: syntax error, unexpected T_FUNCTION” https://secondlinethemes.com/fix-parse-error-syntax-error-unexpected-t_function/ Thu, 18 May 2017 10:37:08 +0000 http://secondlinethemes.com/?p=349 Need help with your WordPress Project? Hire an experienced developer today! Many times, when installing a new plugin or theme, you may encounter the Parse error: syntax error, unexpected T_FUNCTION error. This error is basically indicating you that there’s something wrong in one of your functions. Most of the times, you should also get the […]

The post Fix “Parse error: syntax error, unexpected T_FUNCTION” appeared first on SecondLineThemes.

]]>
Need help with your WordPress Project? Hire an experienced developer today!

Many times, when installing a new plugin or theme, you may encounter the Parse error: syntax error, unexpected T_FUNCTION error. This error is basically indicating you that there’s something wrong in one of your functions.

Most of the times, you should also get the exact located of where the error actually appears – Parse error: syntax error, unexpected T_FUNCTION in /public_html/wp-content/themes/custom-theme-name/functions.php on line 123.

Fixing the “Parse error: syntax error, unexpected T_FUNCTION” Error

There are multiple ways in which you could fix the “Parse error: syntax error, unexpected T_FUNCTION” error. We’ll explore the different methods here, but first, let’s discuss the actual origin of these errors. Basically, the T_FUNCTION error appears whenever there’s some syntax errors within your plugin or theme files. It can either be a non-valid part of your code, or alternatively the plugin or theme is trying to use features of a more advanced PHP version than the one actually installed on your server.

Method 1: Upgrading Your PHP Version (Recommended)

This method would be the best way to solve the “Parse error: syntax error, unexpected T_FUNCTION” error. Specifically if it really originates from a use of new PHP features while you are running an outdated version. Running an updated PHP version could both solve these errors and upgrade your performance, so it’s a double win for you!

Most hosts would allow you to manually change the PHP version via the cPanel:

  1. Log in to your hosting provider cPanel
  2. Look for the PHP Configuration button
  3. Manually select the a newer PHP version. We recommend PHP7 if available, but otherwise try to make sure it’s 5.4+

If you don’t have access to the cPanel, or prefer that the hosting provider deals with it, you can try contacting them by email with the following message:

Hello,

I’m an admin of a WordPress site hosted on one of your servers. Unfortunately, I get many errors due to my outdated PHP version. I’ll deeply appreciate if you could help me upgrade my PHP version to PHP7 if you support it. Otherwise, 5.4+ would be also acceptable.

Can you please let me know if it would be possible to upgrade my PHP version?

Your help is much appreciated.

Method 2: Deleting the function located in the error message

As mentioned above, you can usually see the exact path of the error – Parse error: syntax error, unexpected T_FUNCTION in /public_html/wp-content/themes/custom-theme-name/functions.php on line 123..
Now, you can browse to the full path by using an FTP Client, and edit the file mentioned in the error (in our example, it is the functions.php file, on line 123). Then, check the function or the few lines of code that are located there, and comment them out. This should work well for non-important functions. Unfortunately in case we deal with core features of your theme/plugin you will have to use Method 1 and upgrade your PHP version.

 

If you need a savvy WordPress developer to help you out, please consider Hiring an Expert.

The post Fix “Parse error: syntax error, unexpected T_FUNCTION” appeared first on SecondLineThemes.

]]>
Fix WordPress White Screen of Death https://secondlinethemes.com/fix-wordpress-white-screen-death/ Tue, 09 May 2017 10:00:49 +0000 http://secondlinethemes.com/?p=346 The WordPress White Screen of Death may appear for several reasons: PHP errors, lack of server resources, broken file structure etc. In this article, we’ll figure out how to Fix the WordPress White Screen of Death rapidly without having a long down-time. The WordPress White Screen of Death errors and issues can be painful, especially […]

The post Fix WordPress White Screen of Death appeared first on SecondLineThemes.

]]>
The WordPress White Screen of Death may appear for several reasons: PHP errors, lack of server resources, broken file structure etc. In this article, we’ll figure out how to Fix the WordPress White Screen of Death rapidly without having a long down-time.

The WordPress White Screen of Death errors and issues can be painful, especially on shared web hosting servers. It is one of the most common errors on WordPress. Why? Mainly because of their security measures. Hosting companies make it twice as hard to track down the error, and see what’s actually broken. Many errors can invoke the weird, and quite common “WordPress White Screen of Death”. Quite a poetic name for an error, isn’t it? This happens when you go to your website, or some address on your domain, and the page loads, yet nothing is really rendered. You get a white screen – hence the name. Often times, you might even get locked out of your website. Let’s see why this issue occurs, and how we can fix it.

If you’re looking for 24/7 WordPress support for podcast websites, WPBuffs is on of the most recommended services out there that would help you avoid these kinds of fatal error.

Fix the WordPress White Screen of Death

Even though the user sees a blank white page, there is usually some sort of a PHP error displayed behind the scenes. But this warning, fatal error or notice is blocked/automatically hidden by the hosting provider, so they can avoid vulnerabilities or exposure of server configuration. That’s how things are set in the world of shared hosting. Companies have to be very, very careful — since hundreds of websites depend on a single PHP/server configuration.
If you are on a VPS, you can tweak PHP’s settings, and actually see through the white screen of death. So, what can cause this error? A handful of things come to mind, starting with exhausted memory and bad server configuration, to faulty plugin or bad-coded theme. Let’s see how we can identify the problem and fix it, so that our website can properly render.

Possible Solutions

Now if you don’t want to tinker with debugging, which is totally fine for people who are not comfortable with debugging and changing code, there are a few general tricks you could try to get rid of the WordPress White Screen of Death. Let’s check them out.

Increase the Server’s Memory Limit

Increasing the server memory isn’t a too complicated process but it can help you solve the WordPress White Screen of Death. In a nutshell, you have to locate PHP configuration file, modify a directive’s value and restart Apache. You can read some further info on the basic PHP settings here.

Disabling All the Plugins

Like mentioned at the beginning of the article, the most probable cause of this error is a faulty plugin or a theme related error. The fastest way you can cross this out, is to disable all the plugins on your website, and see if the error is gone. Go to the Plugins page, and you can check/uncheck a single checkbox and select all the plugins. Once you do that, click on the multiple actions drop-down option, and select deactivate. Now try to open the page with the WordPress white screen error, and see if it loads properly. If it does, you can try to activate your plugins one by one, until you see which one is causing the error.

In case the White Screen of Death is showing when you try to open the WordPress dashboard, or it is showing across every page on the website, you can login on the server via FTP, and download all the plugins at first, and then delete them one at a time, or rename the folder names to see at which point in time the white screen issue disappears.

Important: Make sure to backup everything in your /wp-content/plugins folder, before you start removing and uploading plugins back.

Change Your Theme

You can try changing your currently active theme. Go to Appearance->Themes, and select a different one — just to see where the problem is. If changing the theme fixes the white screen issue, you can contact the developers, or maybe downgrade to a previous version, until they fix the bug.

Some core debugging

If you want to skip guessing, and checking out dozen of things to see if they are broken, the first thing to do is to try to modify the PHP configuration. You should look for debugging and error handling settings in the php.ini file, and check whether they are turned off. This might be tricky or entirely forbidden in shared hosting environments, but if you have the access, it is worth checking out.

One other thing to do, is to open wp-config.php, and find the WP_DEBUG global variable — which should be initially set to false. Set it to true, and save the file. This variable controls error handling, and when you set it to true, WordPress should start displaying errors, issues and warnings on your site. Now try to refresh your website and see whether some sort of error is displayed. In most cases, this is where the white screen of death stops being just white. There is some sort of a error message that gives further details on what needs to be fixed, to get your website up and running.

The error message should give you a pretty good idea of what’s wrong, whether it’s a plugin, something you did in code, or your theme. There is also a hint in which file and on which line the error took place, when the code was interpreted. Let’s try to visualize this, and see what you might get:

Fatal error: Call to undefined function in file /plugins/plugin-name/functions.php on line 233.

This means that you should probably either fix what your plugin is doing wrong, or disable it, to see whether the “white screen of death” error is gone.

The post Fix WordPress White Screen of Death appeared first on SecondLineThemes.

]]>
Fix WordPress Import Navigation Issues in PHP7 https://secondlinethemes.com/fix-wordpress-import-navigation-issues-php7/ Thu, 06 Apr 2017 11:44:52 +0000 http://secondlinethemes.com/?p=340 There are many reasons why the WordPress Import plugin or custom plugins that are based on the default WordPress Import would fail. Sometimes there are issues with the server, such as insufficient memory or timeout limits. In other cases, the import file itself is too large. In this article, we’ll focus on the WordPress Import […]

The post Fix WordPress Import Navigation Issues in PHP7 appeared first on SecondLineThemes.

]]>
There are many reasons why the WordPress Import plugin or custom plugins that are based on the default WordPress Import would fail. Sometimes there are issues with the server, such as insufficient memory or timeout limits. In other cases, the import file itself is too large. In this article, we’ll focus on the WordPress Import not importing properly Navigation menu items. This usually happens when you’re using PHP7 on your server. The entire WordPress Import process seems to be completed properly, but there are no navigation menus imported.

Fix WordPress Import issues with the Main Navigation

If you have PHP7 installed on your server, the WordPress Importer plugin would probably fail to import menu/navigation items. Although this works flawlessly on earlier versions of PHP (5.4+), people who made the migration to PHP7 encountered this error. It is a really easy fix, so let’s get started.

When you try to import menu items with the plugin on PHP7, you’ll get the following error:
Notice: Array to string conversion in /wp-content/plugins/wordpress-importer/wordpress-importer.php on line 798

Custom WordPress Import plugin? Not a Problem!

Note that if you are using a 3rd party plugin, that many premium themes come with, you can still change the import file. Try to find the WordPress Import script or file, and make sure to edit it. It can be embedded within plugins such as ‘One Click Importer’ that are often bundled within premium themes, as mentioned above.

Modifying the Code

To make this error disappear and fix the issue, open the wodpress-importer.php file in your favorite text editor, navigate to line 798, and apply the following change:

Change

$$meta[‘key’] = $meta[‘value’];

To

${$meta[‘key’]} = $meta[‘value’];

Once you save the file, reload WordPress and everything should work fine.

Note – For further reading, you can check out the original ticket opened in the Make WordPress Core

The post Fix WordPress Import Navigation Issues in PHP7 appeared first on SecondLineThemes.

]]>
Can’t Upload Theme – “Are you sure you want to do this” Error Fix https://secondlinethemes.com/cant-upload-theme-sure-want-error-fix/ Tue, 21 Mar 2017 11:00:13 +0000 http://secondlinethemes.com/?p=326 The “Can’t Upload Theme – Are You Sure You Want To Do This?” error appears quite regularly for WordPress users, however it should be fairly simple to solve. WordPress is written in PHP, which is a server-side scripting language that’s popular on the web. If you bought a theme and tried to upload the zip […]

The post Can’t Upload Theme – “Are you sure you want to do this” Error Fix appeared first on SecondLineThemes.

]]>
The “Can’t Upload Theme – Are You Sure You Want To Do This?” error appears quite regularly for WordPress users, however it should be fairly simple to solve. WordPress is written in PHP, which is a server-side scripting language that’s popular on the web. If you bought a theme and tried to upload the zip file using the WordPress uploader, you might run into the famous Can’t Upload Theme error. This error is very common, and your PHP setup is the probably the main reason behind it. To be more precise, The initial PHP configuration on most servers limits large file uploads – hence you are not allowed to upload your theme if it is larger than, let’s say, 2MB.

Fixing the Can’t Upload Theme – “Are you sure you want to do this” Error

The first solution is for people who have SSH access to their servers and are comfortable with using the terminal and vim. The second solution is for people that don’t want to play with server configuration files, and prefer an easier, GUI approach using an FTP client.

Option 1: Modify PHP Configuration (VPS/Dedicated Hosting)

Depending on the package you have, hosting providers allow you to change PHP’s configuration files. But this often applies to VPS and dedicated hosting plans that have SSH access. Shared hosting can be tricky to configure, as you’re on a server with tons of other people and you don’t have the desired control to make changes. That’s why this method is recommended for people with VPS or dedicated hosting plans.

The configuration file we need to modify is called php.ini.

Finding php.ini Location

Login in your server using SSH, and navigate to your document root. For this solution, we will be using an Ubuntu 14.04 LTS server. Provided you have installed all the necessary tools for your WordPress installation, open your document root by:

Command: cd /var/www/html

Once you are in the document root, carefully go through the following steps:

  1. Create an empty file called info.php by typing: sudo touch ./info.php.
  2. Open the newly created file by typing: sudo vim info.php. Once vim opens the empty file, we will write a single line of PHP code. Press I to enter the Insert Mode in vim, and then write: <?php php_info(); ?> . To save these changes, press Esc, then write :wq and press Enter. This will tell vim to write the changes and quit.
  3. Go to you domain or IP address, and open up this file by typing: www.mydomain.com/info.php
  4. Once it opens, look for Loaded Configuration File. It will be somewhere in the beginning of the listed configuration. This will tell us where the php.ini file is stored on our server. It should look something like: /etc/php5/apache2/php.ini. Make sure to copy or remember this path.

IMPORTANT: Once you know the path, you need to remove the info.php file, because other visitors can type the same URL that you entered and see your PHP configuration. It can make your website vulnerable to all types of attacks.

To remove the info.php, open your terminal again, make sure you’re still in the document root (if not, navigate back to it), and write:

Command: sudo rm ./info.php.

Modifying php.ini

Now that we know where our main configuration file lives, we will open it with vim, just like we opened info.php, and make some changes to it.

Steps:

  1. Open php.ini. Write the following command to open php.ini: sudo vim /etc/php5/apache2/php.ini. Remember, this is the path from info.php. It may be different in your case.
  2. The command above should open a pretty large file. Press I to enter insert mode of vim, and scroll until you find the following 2 variables (lines): post_max_size and upload_max_filesize. Their default values should be 8M and 2M. And this why your theme wouldn’t upload. Since you’re in insert mode, replace the default values to 30M on both variables.
  3. Common thing to do, is to increase the memory limit as well. Find the memory_limit variable, and increase it depending on how much RAM your server has. The default value of memory limit should be 128M. You can change that to 256M.
  4. Once you made these changes, press Esc to exit Insert mode, and write :wq to save the changes.
  5. Final step is to restart apache (our web server), so that these changes can take effect. Write the following command: sudo service apache2 restart. If you’re using a newer Ubuntu server (i.e. 16.04 LTS), the command is slightly different: sudo systemctl restart apache2.service.

You’ve made it! Now that we changed the upload file limit, you can upload your theme without any problems using the WordPress uploader.

Option 2: Upload Theme via FTP (Shared Hosting)

If you are on a shared hosting, or maybe you don’t want to mess around with server and PHP configuration, there is a simpler way to upload your theme. This solution involves creating an FTP account in your cPanel, and using an FTP client.

Login into your cPanel, and find the FTP Accounts section. There’s a good chance that your hosting provider already created a default FTP account for you. If so, you can use that one with your login password, or create a new one by inserting a path, username and a password.

The important thing here, is to get the FTP credentials that will allow you to login and upload the theme. There are 3 credentials that FTP clients ask for: server, username and password. You can get all these from the FTP Accounts section in your cPanel.

Now that you have an FTP account, it’s time to put it into use. There are many FTP clients around, both paid and free. If you’re on a Mac, I would suggest Cyberduck, a free FTP solution with great user interface. If you’re on Windows, check out FileZilla.

Regardless of which client you pick, once you install it and open it, find the Open/New Connection tab. Once you click on Open Connection, populate the following files accordingly:
Protocol: Choose File Transfer Protocol (FTP)
Port: This should be pre-populated for you, but in case it isn’t, the File Transfer Protocol uses Port 21 for incoming connections.
Server: This is the server field from your FTP Accounts. Often, hosting providers set the server name as the domain name – without the “www”. So, it could look something like mydomain.com.
Username: The FTP username
Password: The FTP password

Once you hit connect, you should see your root directory (which was /var/www/html in our case – as seen in the first solution). From there, you can click between directories just as you would do in your OS. This is much easier from navigating between files and directories using the terminal like we did above.

Unpack your zip theme file in your computer, and navigate to /wp-content/themes/ in the FTIP client on the server. Now simply drag and drop the unzipped folder into the theme’s directory, and wait a few minutes for the transfer to complete. Note that the theme is larger, the transfer could take up to 1 hour to complete. Your internet connection speed is also important.

As soon as the transfer finishes successfully, you can go to WordPress Dashboard -> Appearance, and find your theme there. Then, simply activate the theme and you should have everything fully working.

Note: Make sure that the transfer was completed successfully and error-free. FTP can be a fragile process, and clients can stop the connection or transfer to the server if something’s wrong. You can make sure that everything went fine by checking out the client’s transfer console.

If you keep getting interrupted, you would need to remove the files that are already transferred on the server, and start over – until the theme is 100% uploaded to the server.

The post Can’t Upload Theme – “Are you sure you want to do this” Error Fix appeared first on SecondLineThemes.

]]>
Disable the WooCommerce Cart Icon https://secondlinethemes.com/disable-the-woocommerce-cart-icon/ Mon, 13 Mar 2017 18:38:47 +0000 http://secondlinethemes.com/?p=321 Need help with your WordPress Project? Hire an experienced developer today! WooCommerce doesn’t provide an option to Disable the WooCommerce Cart Icon from the header or navigation. In this article, we will discover a very quick and easy workaround by adding a few lines of custom CSS. This technique will help you to hide/remove other […]

The post Disable the WooCommerce Cart Icon appeared first on SecondLineThemes.

]]>
Need help with your WordPress Project? Hire an experienced developer today!

WooCommerce doesn’t provide an option to Disable the WooCommerce Cart Icon from the header or navigation. In this article, we will discover a very quick and easy workaround by adding a few lines of custom CSS. This technique will help you to hide/remove other elements from your website as well. FYI, you don’t really need to know how to code to do this. Let’s get started!

We’ll need to do 2 things here:
1. Inspect/find the cart icon via your browser’s inspector
2. Apply a custom CSS rule to hide the cart icon

If you are using one of our WordPress Podcast Themes, you can find additional settings through the “Appearance > Customize” screen.

How to Disable the WooCommerce Cart Icon in Your Code

Browsers make it pretty easy to inspect and manipulate elements in the DOM. What is the DOM? Well, it stands for Document Object Model, but in layman’s terms, it is a hierarchical representation of every element on the website in a tree-like form.

Browsers allow us to review the entire structure of a web page including all elements and their properties. But in this case, we want to select a specific element — the cart icon. Let’s see how we can do this in Safari and Google Chrome without searching for it manually in the Element Inspector.
In Safari, you should have the Developer tools enabled first.

The steps to disable the WooCommerce Cart Icon

1. Open your website, and once it is fully loaded, right-click anywhere on it, and select Inspect Element.
3. On the right side, you’ll see an icon that looks like a sniper scope, however iIf you hover it, it will say Start Element Inspection. If more convenient, you can also press Shift + Cmd + C. Once this icon is active, you will notice as soon as you move your mouse over some section or element on the website, the browser starts to highlight those elements.
4. With the Element Inspection active, find the WooCommerce cart icon in the header, and click on it. Once you do this, the browser will automatically find the icon element in the DOM tree.
5. From here, we can easily see what CSS classes are associated with the WooCommerce cart icon, and modify them later in our WordPress admin panel. If you take a closer look at the highlighted element, you will see that it has a class called header_cart. And on the right side, you can see all the CSS properties applied to it.

In Chrome, the process is pretty much the same. The only difference, is that to find the cart icon element, you will need to click on the arrow icon on the very left called Chrome Element Inspector (as opposed to Safari’s Start Element Inspection option).

Now we know how to track down any element on our website, and see stuff like CSS properties and HTML attributes related to it.

Custom CSS to Disable the WooCommerce Cart Icon

We found out that the WooCommerce icon has a class called header_cart. Now all we need to do, is add a single line of CSS to that class. Generally, you can find the Custom CSS option in Appearance -> Theme Options. In the Custom CSS text area in your theme’s options, you will need to add:

.header_cart { display: none; }

Click Save Changes, and reload your website. The icon should be gone. If it is still there, try:

.header_cart { display: none !important; }

Next, if the icon is still there, the browser might have cached CSS and JS files from your website. These files are called static files. You will need to empty the cache manually in the browser settings, and reload again to see the custom CSS you wrote take effect.

Special Case

Sometimes, when the second solution doesn’t work, or you can’t seem to Disable the WooCommerce Cart Icon while using smaller browser sizes, there might be some CSS queries overwriting the properties of this class. You will need to use the Element inspector, and find those queries. Here’s an example:

@media (max-width: 767px) {…}

To modify this query, in the Custom CSS field, add the following lines (bellow the first .header_cart line):

@media (max-width: 767px) {
		.header_cart { display: none; }
	}

 

If you need a savvy WordPress developer to help you out, please consider Hiring an Expert.

The post Disable the WooCommerce Cart Icon appeared first on SecondLineThemes.

]]>
Enable and Disable the WooCommerce Sidebar https://secondlinethemes.com/enable-disable-the-woocommerce-sidebar/ Tue, 28 Feb 2017 10:00:15 +0000 http://secondlinethemes.com/?p=317 Need help with your WordPress Project? Hire an experienced developer today! WooCommerce can be a little tricky when dealing with the WordPress sidebar positioning and display. If you’re looking for a way to disable the WooCommerce sidebar, and make your Woocommerce pages full-width, get ready to do some tweaking! We will cover the right and […]

The post Enable and Disable the WooCommerce Sidebar appeared first on SecondLineThemes.

]]>
Need help with your WordPress Project? Hire an experienced developer today!

WooCommerce can be a little tricky when dealing with the WordPress sidebar positioning and display. If you’re looking for a way to disable the WooCommerce sidebar, and make your Woocommerce pages full-width, get ready to do some tweaking! We will cover the right and wrong ways to disable or remove the sidebar from your Woo Pages, and make your shop look awesome! But first, let’s see how you can enable the sidebar, in case you messed something up.

Using one of our Themes?

If you are using one of our Podcast Themes, for example the Tusant WordPress Theme, you can easily change the WooCommerce settings in the page you use as the shop page under the “Page Options” panel. Also, you’ll find a bunch of additional settings in the “Appearance > Customize” screen.

Enabling the Sidebar

The WordPress sidebar should be active by default. If not, you might need to go to Dashboard → Appearance → Widgets, and add some widgets to the sidebar to make it visible. WooCommerce comes with custom widgets that you can select called “Show Overview Page” and “Single Product Page”. Just drag & drop them in your sidebar, and they should appear in your store.
Also, you might need to go to the page in question, and select a template with a sidebar. This can happen when you have a Shop page that’s using a full-width template (without a sidebar).

Disable the WooCommerce Sidebar

There are a couple of different options you could use to disable the WooCommerce sidebar. We’ll go over all the options and show you how to disable the WooCommerce sidebar on your own:

The “Wrong” Way

There’s a good chance you read somewhere that the easiest way to remove the sidebar is to use the following lines of CSS:

.single-product .sidebar {
		display: none !important;
	},

or even something like:

.woocommerce #sidebar {
		display: none;
	}

The first snippet will hide the sidebar from your single product pages, while the second will hide it altogether on every WooCommerce page on your WordPress website. But the trick here, is that even though you won’t see the sidebar, it will still be rendered and take up space in your template. This is because CSS can’t stop an element from being rendered – it can just hide it. Also, this would not necessarily work for all themes, and if you’re using a custom theme it may not work properly so make sure to double check that.

The Right Way to Disable the WooCommerce Sidebar

To properly disable the WooCommerce sidebar, we’ll need to write some PHP code, and manually change what WordPress should render on the front-end. Here are a couple of solutions:

1. Disabling Sidebar Using a WordPress Hook (Recommended Method)

This is the best solution, and it is considered to be the “WordPress way” of doing things. Navigate to your theme’s functions.php file, and write the following code:

function disable_woo_commerce_sidebar() {
	remove_action( 'woocommerce_sidebar', 'woocommerce_get_sidebar', 10); 
}
add_action('init', 'disable_woo_commerce_sidebar');
2. Disabling Sidebar in a Custom Template that Displays WooCommerce Products Alongside Regular WordPress Posts

You can use the is_woocommerce() function to detect whether the current page that’s being accessed is a WooCommerce template or not. The function will return true if it is a Woo page, and false otherwise. So in our theme’s sidebar.php, we could write:

	if ( !is_woocommerce() ) {
		get_sidebar();
	}

Using this logic, we can easily determine what type of page the user is accessing, and based on that, we can call the function that renders the sidebar. So let’s say that you open a product page (which is a WooCommerce template). Then the expression within the if statement will return false, and the sidebar function won’t be called – meaning the sidebar won’t be rendered.
How does the !is_woocommerce() return false? Well, the is_woocommerce() function will return true, and the ! (not) operator will convert the “true” into the opposite value, which is false.

3. Disabling Sidebar in a WooCommerce Template

Navigate to woocommerce/templates/shop, and open up the sidebar.php file. Here, you need to comment out everything in the sidebar.php file using /* at the very top, and */ at the very bottom of the file. Save it, and see if it worked on the front-end.

 

If you need a savvy WordPress developer to help you out, please consider Hiring an Expert.

The post Enable and Disable the WooCommerce Sidebar appeared first on SecondLineThemes.

]]>
Change WooCommerce Product Image Sizes https://secondlinethemes.com/change-woocommerce-product-image-sizes/ Sun, 19 Feb 2017 13:53:05 +0000 http://secondlinethemes.com/?p=313 Need help with your WordPress Project? Hire an experienced developer today! If you are working on a new project with WooCommerce, and notice that some of the images look blurry or stretched, or if you simply wish to change the size of the default WooCommerce product image sizes, you will have to setup or modify […]

The post Change WooCommerce Product Image Sizes appeared first on SecondLineThemes.

]]>
Need help with your WordPress Project? Hire an experienced developer today!

If you are working on a new project with WooCommerce, and notice that some of the images look blurry or stretched, or if you simply wish to change the size of the default WooCommerce product image sizes, you will have to setup or modify thumbnail/image sizes. In this article, we’ll cover changing both the WooCommerce product image sizes and the default WordPress image size you might need to change. Let’s see how you can change the default image sizes of your theme first, and then, we’ll look into how to do the same exact thing for WooCommerce product image sizes.

If you’re still new to WooCommerce, we’d recommend that you find some online resources and learn how to launch your online store with it – it’s easy!

Changing the WooCommerce Product Image Sizes

In WooCommerce, all you need to do is go into the WooCommerce->Settings->Products->Display section. This is where you will see the existing dimensions for Catalog Images, Single Product Images and Product Thumbnails. Set those sizes accordingly, hit Save Changes, and afterwards, regenerate (delete and insert one more time) your product thumbnails. In order to regenerate the product thumbnails, you’ll need to use a plugin such as Force Regenerate Thumbnails. Simply install the plugin and run it one time. Your WooCommerce product images should be updated right after doing that!

 

Changing Default Image Sizes in a WordPress Theme

In case your existing thumbnail size are not looking alright for you, or if you need to add an entirely new default thumbnail size, navigate to your theme’s root directory and open the functions.php. Then, at the bottom of the file, we will write a simple function and hook it to the appropriate action:


function our_custom_thumbnail_sizes() {
	// Set small thumbnail size
	add_image_size('slt-small-thumbnail', 180, 150, true);
	// Set medium thumbnail size
	add_image_size('slt-medium-thumbnail', 220, 170, true);
	// Set large thumbnail size
	add_image_size('slt-large-thumbnail', 1600, 800, true);
}
add_action(‘after_setup_theme’, ‘our_custom_thumbnail_sizes’);

Once you get the concept of how the default thumbnails work on WordPress, it would be super easy to customize and fit to your needs. Furthermore, you can adjust these images in various ways, such as to allow cropping or not.
Lastly, in order for these changes to take effect, you need to remove the existing post thumbnails, and add them again into your pots.

 

If you need a savvy WordPress developer to help you out, please consider Hiring an Expert.

The post Change WooCommerce Product Image Sizes appeared first on SecondLineThemes.

]]>
Fix Revolution Slider Error: slider_export.txt does not exist! https://secondlinethemes.com/fix-revolution-slider-error-slider_export-txt-not-exist/ Mon, 30 Jan 2017 22:25:16 +0000 http://secondlinethemes.com/?p=302 Need help with your WordPress Project? Hire an experienced developer today! The revolution slider plugin comes with 2 types of export files. The first type are export examples that are included in the package called Download — under the exports folder. These files are compressed with ZIP, and import the slider, its settings, images and […]

The post Fix Revolution Slider Error: slider_export.txt does not exist! appeared first on SecondLineThemes.

]]>
Need help with your WordPress Project? Hire an experienced developer today!

The revolution slider plugin comes with 2 types of export files. The first type are export examples that are included in the package called Download — under the exports folder. These files are compressed with ZIP, and import the slider, its settings, images and everything else needed for the plugin to work. The other type of export files are file-based, which means they have extensions like .txt, .css, etc. If you encountered the error “slider_export.txt does not exist!” while installing the plugin or importing a custom slider, there are a few things you can do to troubleshoot the Revolution slider, and fix this issue.

Solution 1 – Fix the “slider_export.txt does not exist” error

This solution should work most of the time. Here are the steps:

  1. Unzip the slider file (Slider.zip) into a folder.
  2. In WordPress under Revolution Slider, click on Import Slider and instead of uploading the whole unzipped file, upload only slider_export.txt.
  3. Login with your FTP client to your server, and navigate to wp-content/plugins/revslider/rs-plugin/css. Here, upload/overwrite the following 2 CSS files: dynamic-captions.css and static-captions.css. You can find these files in the folder where you unzipped the slider file from Step 1.
  4. Upload the images (if any image is included within the slider) folder to: \wp-content\uploads\201X\YZ. (* Note – Make sure to upload the images to the proper folder according to the dates)

Solution 2

Sometimes, this Revolution Slider error can also occur due to insufficient file permissions on your server for the uploads directory in wp-contents. To fix it, you need to change the permissions to 755 of the uploads directory and its subdirectories, and 644 permissions for the files inside it. But before you do this, you need to check the existing permissions of the uploads directory and its files. (Note – this solution may be complicated for some users, so it is highly recommended that you contact your hosting provider if the issue persists.)

Understanding and Checking File Permissions

You can easily check the file permissions by navigating to your server and running a simple command ls -l. For instance:
1. cd public_html/wp-content
4. ls -l. This command will list all directories in wp-content with their permissions.
To turn a file permission like this drwxr–r– to a number format, you need to remember 3 simple rules:
r means Read and it is equal to 4.
w means Write and it is equal to 2.
x means Execute and it is equal to 1.

UNIX/Linux environments always represent file/directory permissions in this format (rwx). Each file and directory has permissions for owner, group and world. This means that permissions are separated into 3 sections, and each of those sections applies to a different type of user. So, let’s translate something like drwxr–r– into a number. First we will break it down, so it is more obvious:
drwx r– r–
The owner has rwx, the group has r– and world has r–.
Note: The “d” at the beginning means that we’re talking about a directory, and not an ordinary file. A dash (-) means “no permission”, with one exception. If you see a dash (-) at the beginning of “rwx” expression instead of “d”, that indicates a file.

In plain English, this means that the owner of the directory has read-write-execute, while the group and world have only read permissions. If you take a look at our 3 simple rules from above, you can easily translate this sequence of permissions into a number: owner(read(4) + write(2) + execute(1) = 7), group(4) and world(4). This means that the uploads folder has 744 instead of 755 permissions, and we need to change that.

Changing File Permissions

If you found out that your directory and file permissions are not 755 and 644 respectively, you need to change them. To do that, SSH to your server using your terminal, navigate to the wp-content directory and type:
find uploads -type d -exec chmod 755 {} \;
once that’s executed, type
find uploads -type f -exec chmod 644 {} \;
The 2 commands above will find the uploads folder and change file permissions to 755 for folders and 644 for files recursively.

 

 

If you need a savvy WordPress developer to help you out, please consider Hiring an Expert.

The post Fix Revolution Slider Error: slider_export.txt does not exist! appeared first on SecondLineThemes.

]]>
3 Steps for Advanced Custom Fields Integration https://secondlinethemes.com/3-steps-advanced-custom-fields-integration/ Sun, 22 Jan 2017 18:57:10 +0000 http://secondlinethemes.com/?p=296 Custom Fields in WordPress with Advanced Custom Fields – Once you created a custom post type and taxonomy, it is time to add some special fields to it, and further customize WordPress to fit your needs. These custom fields in WordPress help you build new functionality to your site by creating populating different field types […]

The post 3 Steps for Advanced Custom Fields Integration appeared first on SecondLineThemes.

]]>
Custom Fields in WordPress with Advanced Custom Fields – Once you created a custom post type and taxonomy, it is time to add some special fields to it, and further customize WordPress to fit your needs. These custom fields in WordPress help you build new functionality to your site by creating populating different field types in the admin panel. What type of field types? From text, textarea, checkbox, radio and select, all the way to files, images, galleries and color pickers.

Once you have these fields tied up to your custom post type, and you insert some values, you can easily display them in front-end pages. For instance, we can create a custom price and discount text fields for our post type, and then, display them anywhere we like in our template. Let’s see how we can do this using one of the best rated plugins in the WordPress directory — Advanced Custom Fields.

1. Advanced Custom Fields Introduction

Advanced Custom Fields is a free plugin for visually creating and managing custom fields in WordPress. Moreover, it is a framework with great plugins (add-ons), documentation and community. ACF has a really simple and powerful API with functions for everything you’d possibly need, in order to manipulate the custom fields and their values. Each of these functions are explained in detail and demonstrated with an easy-to-follow examples.

To install the plugin, follow this link. Once you activate the plugin, visit ACF’s page in the admin panel.

 

2. Creating Custom Fields

Go to Custom Fields, and click on Add New to create a new field group. Let’s name the field group Reviews CPT — the name of a custom post type we created in one of the previous articles. Now, we can start adding custom fields to it. For starters, we’ll create two fields: price and discount. Click on the +Add Field button, and set the values as follows:

  • Field Label (required), is the name that will appear in the post edit page. We can set it to Price.
  • Field Name (required), is the “slug” that must be a single word with no spaces. Dashes and underscores are allowed. This is the name we’ll use to access this field’s value in the front end. Let’s set this to review-item-price.
  • Field Type (required), is one of the field types we mentioned in the intro of the article. You have a lot of choices here, so pick accordingly. For this example, we will set the field type to number.
  • Field Instructions (optional), is the description box that will help authors who submit data into the fields. Set it to something like: Here goes the price of the item that’s being reviewed.

As you choose different field types, additional options will be displayed to further customize your field. For example, if you pick a text field type, you can specify stuff like default value, prepend, append and character limit.

Repeat the same process to create the discount custom field. You can set its type to text, and slug to review-item-discount.

Once finished with the second field, we can let ACF know which custom post type we want to link with these fields. This is the location box. Use the following logic:

Show this field group if: Post Type is equal to reviews.

This will make the custom fields accessible only in our reviews post type, when we’re trying to add a new article.

The final step is to click Publish, visit the Reviews section on the admin panel and click on Add New Review (or Add New). Once you do this, you will notice the 2 fields in the bottom — right bellow the WYSIWYG editor. Create a review with these values and publish it.

 

3. Displaying Custom Fields

There are million things you can do with these fields, but for the sake of just getting started with ACF, let’s just display them on the single post page.

Navigate to your theme files, and if you haven’t already, create a single-reviews.php file (single-{post_type_name}.php). This will be a custom template file specifically for the reviews post type, and the place where we display our custom fields.

Why not use the already existing single.php? Because this template file applies to every post type on our website. Remember that we specified in the plugin to only show the fields in our reviews CPT. When you open a regular post type, the values won’t show up.

Copy all the contents of single.php into single-reviews.php. Then, in single-reviews.php add the following code, 1 line upper from the_content() function:

<?php if (get_field(‘price)): ?>

Item price: <?php the_field(‘price)); ?>

<?php endif;?>

The get_field() function will return the value of the specified field. This is good, because we can check whether a value is defined, before we try to display it. If the field doesn’t have a value, the function will return a false, and the if statement won’t execute. At the end, the_field() simply echoes the field in a h2 tag. You can repeat the same process for the discount field.

When you visit your article, you should see a Price: $600 and Discount: 20% (or whatever values you put) before the review content. Pretty powerful, isn’t it!

The post 3 Steps for Advanced Custom Fields Integration appeared first on SecondLineThemes.

]]>
Creating a WordPress Child Theme https://secondlinethemes.com/creating-child-theme/ Fri, 13 Jan 2017 13:51:05 +0000 http://secondlinethemes.com/?p=291 WordPress is open source — meaning you can look up the code and see/improve how the CMS works. However convenient this may sound in theory, very few people would need to change the WordPress core. Themes on the other hand, require tons of tweaking and customizations. If some option isn’t part of the theme’s pre-built […]

The post Creating a WordPress Child Theme appeared first on SecondLineThemes.

]]>
WordPress is open source — meaning you can look up the code and see/improve how the CMS works. However convenient this may sound in theory, very few people would need to change the WordPress core. Themes on the other hand, require tons of tweaking and customizations. If some option isn’t part of the theme’s pre-built admin panel, you will need to make the modification in question manually. And this is where child themes come into play — as the recommended method for customizing any WordPress theme. In this article, we’ll learn how we can create a WordPress child theme by properly enqueuing parent theme styles.

Why You Need to Use a Child Theme?

The most important thing to understand about a child theme, is that it inherits all of the features and appearance from its parent theme. We can make changes to the parent theme — without affecting or changing its code. Why is this important? Because when you modify some files directly and the theme is updated, you may lose your customizations. By using a child theme, you will risk that our changes are deleted or overwritten — no matter how often the original theme gets updated.
Create a WordPress Child Theme — The Right Way
We’re going to create a child theme for the theme Twenty Sixteen. Every WordPress child theme needs 1 directory, and 2 main files: style.css and functions.php. So, let’s do exactly that.

1. From your WordPress root directory, go to wp-content/themes.
2. In the themes directory, create a new folder called twentysixteen-child (or any other name you find suitable). Make sure the name is in lowercase letters. If there’s more than one word, you can separate it with a dash (—).
3. Open your text editor, and within our newly created directory for the child theme, create 2 files: style.css and functions.php.

Now, let’s add a few required comments in our style.css, so that WordPress can detect the child theme:

/*
Theme Name: Twenty Sixteen Child
Theme URI: http://example.com/child-theme-preview
Description: Lorem ipsum dolor sit amet.
Author: John Doe
Author URI: http://example.com
Template: twentysixteen
Version: 1.0.0
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Tags: lorem, ipsum, dolor, sit, amet
Text Domain: twenty-sixteen-child
*/

Although some of these comments are optional, it’s a good practice to include them all. WordPress will use this information to populate some fields in the Appearance section, and to detect the parent theme. Two lines are super-important: Theme Name and the template.

Theme Name is what WordPress will call your child theme throughout the admin panel. The template line is connected with the directory name of the parent theme. So please check your wp-content/themes directory, and see how your parent theme’s directory is named. If you don’t get the template line right, you won’t be able to activate the child theme.

There are two ways we can accomplish this. The first is to use @import in the style.css — which is easier, but with a significant downside. It increases the style load time, and it is no longer the preferred method. That’s why we will enqueue the parent theme styles more efficiently using functions.php.

Open functions.php and write the following code:

function import_parent_theme_styles() {
wp_enqueue_style(‘parent-theme-styles’, get_template_directory_uri() . ‘/style.css’);
}
do_action(‘wp_enqueue_scripts’, ‘import_parent_theme_styles’);

That’s it! Save functions.php, and activate your child theme. It should look exactly the same as your parent theme. But now, whenever you want to change the appearance, you can do that by writing CSS into your child theme’s style.css. Moreover, you can change entire template files in your child theme, and WordPress will know to load those, instead the template files in the parent theme.

The post Creating a WordPress Child Theme appeared first on SecondLineThemes.

]]>