Change WordPress User Roles in myPHP

Change WordPress User Roles in myPHP

If you are using WordPress, you may want to change user roles in bulk. But why?

This is down to my own personal experience where I had installed bbpress forum software. It was to start looking at providing support in a forum style.

However, I had not set up the user settings correctly and ended up with 1000’s of my visitors being set to bbpress user role of spectator rather than the WordPress user roles of Subscriber.

This then became a particular problem when I decided to remove bbpress, I had orphaned users all over the place. I needed a solution to change the user role of 1000’s of user accounts without having to go through each one manually.

myPHP Admin

This is where myPHP came in. You can use myPHP to amended data in your WordPress database. In this case, changing all users with spectator as their user role to subscriber.

NOTICE – Before you go any further, you are about to change your core WordPress database, so ensure that you have a good backup before going any further. You have been warned!

To carry this out, you need to login to your hosting cPanel and open up the myPHP Admin app:

myPHP Admin in cPanel
myPHP Admin in cPanel

When you click myPHP Admin it will automatically redirect you to the utility. Using the top menu bar, you should click on the SQL button:

myPHP Admin SQL Button
myPHP Admin SQL Button

This will now take you to the area where you can add your script to make the changes required.

myPHP WordPress User Role Change Script

Below is the script that you can use to update your own WordPress database by changing the users table and taking any user with bbp_spectator and changing it to subscriber.

UPDATE wp55_users
INNER JOIN wp55_usermeta
ON wp55_users.ID = wp55_usermeta.user_id
SET wp55_usermeta.meta_value = 'a:1:{s:10:"subscriber";b:1;}'
WHERE
(
(wp55_usermeta.meta_key)='wp55_capabilities'
)
AND
(
(wp55_usermeta.meta_value)="a:1:{s:13:"bbp_spectator";b:1;}"
);

Note that the following will need to be changed to suit your environment:

  • wp55 = this is the WordPress database name
  • SET wp55_usermeta.meta_value = ‘a:1:{s:10:”subscriber“;b:1;}’ = Change the subscriber part to whatever you want the user role to be after the change is made
  • “a:1:{s:13:”bbp_spectator“;b:1;}” = This is the existing user role that you want to change

Once you are happy that everything is correct, you can click the Go button at the bottom right of the SQL page. This will then go off and make the changes you have asked to make.

WordPress Confirmation

Then log in to your WordPress administration portal and check the users, they should now be Subscribers instead of Spectators!

Feedback

If you have any problems with this and you need help, please feel free to leave us a message in the comments section.

If you have found that this has helped you out, then great! Let us know below in the comments!

WordPress – How to Exclude a Category from your Homepage

How to Exclude a Category from your Homepage

Introduction

If you are a WordPress user, you may want to find a way of excluding a certain category from your main homepage. This could be if you post latest news articles but do not want them to clutter up your homepage.

The reason I wanted to exclude a certain category was that I run daily giveaways through a partner site and did not want them on the homepage, as it would just be full of them and none of my other posts!

There are a few methods to carry this out, but I am going to show you how to do this with some simple code. However, if you would rather use a WordPress plugin, then you should check out this part of the article:

Use a WordPress Plugin

WordPress plugins are great and usually very simple to use. However, you have to take into consideration things like:

“Will it slow your website down?”

“Is the plugin secure?”

Will the plugin be compatible with my website?

Will the plugin break my website?

But, let’s be honest, most plugins are perfectly safe so long as they are kept up to date and you should always check out the reviews for them to help you make your decision.

That being said, before I decided to go with the coded method, I did try out these three WordPress plugins and they all did the job perfectly well. However, due to the amount of plugins I use already, I decided that I did not want another one for this process.

Use Code

Some people bulk at the mere thought of adding additional code into the WordPress core files. However, it really is not that complicated to make minor changes to get excellent results.

Category ID

Before you start with any coding, you will first need the category ID of the category you want to exclude from your homepage. This is a unique number allocated to each category within your own WordPress installation.

To get this, go to your WordPress dashboard and go to Posts > Categories:

WordPress Portal Categories Menu
WordPress Portal Categories Menu

You will now see a list of all the categories that you have in your WordPress. Find the category that you want to exclude and then click on the Edit link:

WordPress Edit Category
WordPress Edit Category

This will now take you to the detailed area of the category where you can make a number of changes. However, we are interested in the browser address bar. For this guide I am using Google Chrome, but it should be the same with other browsers like Firefox or Edge.

Looking in the address bar, you will see in the middle of the URL that it has category&tag_ID=530 (530 being my category that I am excluding – yours will be different!):

WordPress Category Tag ID
WordPress Category Tag ID

The number is what you need – this is the ID of the category. In my example above, the category ID that I want to exclude from my homepage is 530.

Backup your WordPress

Now before we go any further, any mistakes here could break your website. So ensure that you follow the instructions carefully, but most importantly, backup your site now! Check out the most reliable WordPress backup service for your business to carry out a backup.

At least then, if the worst was to happen, you can revert your site back.

Theme Editor

Now that you have the category ID of the category you want to exclude from your homepage, you will need to add some code to the functions.php file.

To do this, hover over the Appearance link and then click on the Theme Editor link:

WordPress Theme Editor Menu
WordPress Theme Editor Menu

This will take you to the Theme Editor where you can now edit your themes code. The first thing you will need to do is to look towards the top right of the screen and select from the drop down, the theme that you want to edit. When you have selected your theme from the drop down, click on the Select button:

WordPress Select Theme Drop Down
WordPress Select Theme Drop Down

Once you have done that, you will see a list of files underneath this drop down. Find and click on the file named functions.php:

WordPress Theme Functions File
WordPress Theme Functions File

The code

Now to the left of this area, you will see the code that forms the functions.php file. You should now copy and paste the below code into this functions.php file:

function exclude_category_home($query) {
if ($query->is_home ){
$query->set('cat','-530');
}
return $query;
}
add_filter('pre_get_posts','exclude_category_home');

Note the red -530 part of the above code – this means minus category 530. So yes you guessed it, you need to delete the 530 and replace with your categories ID that you retrieved earlier in this guide.

Once you are happy that you have the correct code in place, you should now double and triple check that there are no syntax errors. Sometimes when copying and pasting code, some special characters can become malformed – especially quote marks and dollar signs like are included in this code. The best thing to ensure everything is correct is to manually delete and type in these special characters.

Now you are really happy everything is correct, go ahead and click on the Update File button at the bottom left of the screen.

Refresh your homepage (clear your caches if you have them in place) and you should now see that the category is no long on your homepage!

Feedback

We would love to hear your feedback on this one so please feel free to leave us a message below in our comments section.

Reasons to Choose Gutenberg for WordPress Website Editor

Gutenberg

Here arrives the good news!  With a release of WordPress 5.2, the Gutenberg Editor has also got new updates. The existing  TinyMCE text editor in WordPress has not achieved many changes from along. And, it is now replaced with  Gutenberg Editor. It is named after Johannes Gutenberg. Movable type printing was initially used by him. … Read more

WordPress Plugin – LinkGather

WordPress-Featured-Post

I am delighted to announce the release of our first ever WordPress Plugin – LinkGather. A few weeks ago I needed a full list of all of our posts’ JetPack wp.me shortlinks. Having around 1500 posts published mean’t that it wasn’t an easy task to just copy and paste the links into a text file. … Read more

How to Export WordPress Shortlinks

How-to-Export-WordPress-Shortlinks

Would you like to export all of your published WordPress posts’ wp.me shortlink URLs to a big list quickly and easily? If so, then this post is for you as we show you how, in a few simple steps, you can get all the wp.me links you want.

WordPress Plugin

We have created a WordPress plugin that carries out this task for you, whenever you want! You can go ahead and download it from our site using the button below:

LinkGather WordPress Plugin

You can also install our plugin from the official WordPress Plugin Repository using the button below:

LinkGather WordPress Plugin

Step by Step Guide

The wp.me links are a module of the JetPack plugin installation. I’m sure most of you are familiar with JetPack but if you do not have this module activated, go into your JetPack settings and active it first.

Prerequisites

You will also need to ensure that you either have FTP access or File Manager access to your WordPress installation. This is because we are going to upload a PHP file to the root of your WordPress installation folder. This is the file that we will then run to gather all the wp.me shortlinks and echo them out into a big list within your internet browser.

PHP Code

Once you are happy that you have upload access to the root of your WordPress installation, go ahead and create a simple text file. You can use the built in Windows Notepad, but I’d suggest that you use Notepad++ and it is much better for writing any sort of code. But please, do not try and use Microsoft Word or Google Docs as this will more than like screw up the PHP code formatting.

Once you have your text file, save it to a location of your choice (Desktop is fine) and you can name it anything you like, but for the purposes of this guide, we will use getlinks.php.

Now copy and paste the PHP code below into the text file:

<?php
include "wp-load.php";
$posts = new WP_Query('post_type=any&posts_per_page=-1&post_status=publish');
$posts = $posts->posts;
header('Content-type:text/plain');
foreach($posts as $post) {
switch ($post->post_type) {
default:
$shortlink = wp_get_shortlink($post->ID);
break;
}
echo "\n{$shortlink}";
}
?>

Please be aware of the syntax formatting though, sometimes it can get a bit screwed up copied from a web browser, just check the speech marks and semicolons etc.

Video Demo

See the video below for a quick example of the formatting to look out for and the full process:

Save the text file again so that the file has the PHP in it.

You should now ensure that the file extension is php and not txt which can be a common mistake to make.

Upload to Your WordPress Installation Root

Connect to your WordPress installation root and upload the getlinks.php file.

Do not put it in a subfolder or it will not work.

You are now ready to get all of your published posts wp.me shortlinks. Just go to your blog URL and then add the getlinks.php file to the end of your URL. So for my blog here, you would use:

https://blog.techygeekshome.info/getlinks.php

This should then go off and gather all the shortlinks – this could be a few seconds or maybe longer depending on the size of your site. My blog here has over 1000 posts and it takes 2-3 seconds to complete.

Your web browser should then show you a big list of all your wp.me links:

wp.me shortlinks output

Removing the Blank Lines

You may notice some gaps in the list, this is expected but you can copy and paste this list into something like Microsoft Excel and then just use the Remove Duplicates option under the Data ribbon:

Microsoft Excel Remove Duplicates

You will then get a pop up telling you how many lines it has removed and how many unique values remain:

Removed Duplicates

You will then have a big list of all your wp.me shortlinks!

Feedback

If you have any problems with any steps of this guide, please feel free to leave us a message below in the comments section and we will try to get back to you as soon as we can.

AMP Reports created with Google Analytics

Google-Analytics-Logo

Are you using AMP but now you want to create AMP reports in Google Analytics? Then this guide is for you!

Accelerated Mobile Pages (AMP) seems to be all the rage at the moment. This is because with the advancement of technology with smart phones and tablets, more people are using the internet on smaller screens than ever and this trend is only going to keep going that way.

So when you browse to a website that is using AMP, you will get a sort of stripped back version, a lite version, something quick and simple to load up on a mobile device.

On our blog, we have actually just started using AMP. We had been testing it for a few months and it has been tricky in getting it right for the look of our site and also for the internal linking. Sometimes the AMP would show up for the landing page, but then clicking on an internal link took the visitor to the desktop version. So if you are going to use AMP, make sure you test everything, including links to ensure that you get it right. We do believe that we now have everything correct and should you be viewing our site on a mobile AMP version, we would love to hear your feedback by leaving us a message in the comments section.

You should also ensure that you have AMP reports available to you from whatever analytics system you are using to keep track of AMP visitors and how they are using your site.

As we were testing our AMP pages, we noticed that there are not many AMP reports available for Google Analytics, which is what we use for our site traffic analysis. This lead us to create our own custom AMP reports for all AMP traffic. We will go through the steps to create this report for your own sites.

Prerequisites

For this to work, you need to ensure that you have setup your site for AMP Google Analytics tracking first. There is a guide on how to do this from Google here. Without this, your AMP reports will just be blank.

AMP Reports in Google Analytics Guide

So, first things first. Login to your Google Analytics portal and head to the Administration page.

Creating the Content Grouping

We are going to use Google Analytics Content Grouping to distinguish visitor hits between AMP and non-AMP.

To do this, we need to create the two content groups, so from within the Administration page, on the right side of the three panels, click on Content Grouping:

AMP Reports Content Grouping

In this section, click on the New Content Grouping button:

New Content Grouping

We then need to build the criteria for our AMP traffic.

So, give the group a name, we will use AMP Content Grouping. Then under Group Using Rule Definitions, give the definition a name, we will use AMP Traffic and then define the rule as Page > Contains > /amp/ – this is assuming your AMP traffic is using /amp/ as its page redirection. If you are using something different, make sure you enter it correctly here.

AMP Reports Content Grouping AMP Traffic

We then need to create our definition for non-AMP traffic. So click on Create a new rule set:

Google Analytics Create a new rule set

Then give the definition a name – we are going to use non-AMP traffic. then we need to set the rule as the opposite as our AMP Traffic rule. So, Page > does not contain > /amp/

Google Analytics content grouping does not contain amp

Then click on the Done button. You should now have two rile definitions, one for non-AMP Traffic and one for AMP Traffic:

Google Analytics content grouping Group Definitions

You can then go ahead and click on the Save button.

Viewing the Reports

Come out of the Administration part of your Google Analytics and then click on the Behavior menu option then click on Site Content and then All Pages:

Google Analytics Behaviour Menu

You will now see the Content Grouping option on the report:

Content Grouping on report

Go ahead and click the none dropdown and select the AMP Content Grouping you have just created:

Google Analytics Content Grouping Dropdown

You should now see the report with the two definitions shown, one for non-AMP traffic and one for AMP traffic. At this point, we would love to show you a screen shot, but we cant – because we do not use AMP so we do not have any AMP traffic! But trust us, if you are using AMP traffic, you will now see the two sets of data.

You can then just use it as it is or start to costomise the report further to suit your requirements.

Feedback

We would love to hear your feedback on this article so come and join us on Facebook or Twitter and let us know what you think!

Move Pagination Directly Under Post in WordPress

Move-Pagination-Directly-Under-Post-in-WordPress

When using the WordPress pagination feature, with some themes it can end up being out of the way and your visitors might not see it. This can cause issues where you visitor will get frustrated and leave your website. This also then starts to push up your bounce rate.

I had this problem so I wanted my pagination buttons to be directly underneath my post, so that it was clear to my visitors how to get to the next page.

Plugin v Code

There are a number of plugins you can use to do this but I already use far too many plugins as it is, so I wanted to code it into my theme.

I started Googling how to do this and I came across a post on Stack Exchange which offered a solution. I tested it out and it worked a treat.

Below is the code that allows you to have your pagination buttons just below your post. This should be copy and pasted into your functions.php file – I suggest adding this to your child theme so that it does not disappear on the next theme update.

Pagination Buttons Code

<?php // move pagination links above other end-of-post content additions, like related posts etc.
function move_pagination( $content ) {
if ( is_single() ) {
$pagination = wp_link_pages( array(
'before' => '<div class="page-links"><span class="page-links-title">' . __( 'Pages:', 'firmness' ) . '</span>',
'after' => '</div>',
'link_before' => '<span>',
'link_after' => '</span>',
'echo' => 0,
) );
$content .= $pagination;
return $content;
}
return $content;
}

add_filter( 'the_content', 'move_pagination', 1 );

Bad Syntax

Please be very aware – if you do copy and paste this code above, check the syntax as the formatting can get a little messed up, always check speech marks as this is normally what get screwed up on copy and pasting from the internet.

Feedback

If you have any questions or comments on this post, please feel free to either leave a comment below or use one of our many social media platforms.

Credithttps://wordpress.stackexchange.com/questions/168498/how-to-add-pagination-in-between-post-and-comments?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa

Newsletter

If you want to be notified when we post more quality guides like this one, sign up to our newsletter and you will receive an email when a new post is live.

Join 520 other subscribers.

Don’t worry, we won’t be filling your inbox with spam and you can unsubscribe anytime you like.

How to Setup your Website with a free SSL Certificate

Redirect your website from HTTP to HTTPS

Security is a must these days and if you have spent as much time as I have on your blog, then you want to ensure that it is safe for your visitors to come to you and submit information, safe in the knowledge that it is protected and secure.

Also as a blogger, traffic is probably very important to you and where do most of everyone’s traffic come from? Google of course.

A third temptation to get you to move over to an encrypted site is the little green padlock in the address bar of your browser and a valid certificate, like our one (taken from Google Chrome browser):

https certificate
Click to Enlarge

So how can you take these two factors and satisfy them both with one simple fix? the answer is very simple, move away from your insecure HTTP setup to a secure HTTPS setup.

I have read many posts and comments on social media where “non-techy” people are scared stiff of making these changes in case it completely screws up their website that they have spent years working on. However, the process is super simple and you don’t need to be a geek or a techy to do it, nor do you need to spend any of that hard earned Google Adsense money.

What I am saying here is that you can set up your site with a secure HTTPS (SSL certificate) connection for completely free. No scams, no clickbait – just simple and free.

What options do you have?

Let’s Encrypt

I must stress here that there are a number of ways you can do this, there is a Let’s Encrypt option which again is free, by may be a bit more complicated. I’ve never used it so it’s not really fair for me to comment too much on it, but it is an option if you want to do some research into it.

Hosting Providers

You can of course log a support ticket with your own hosting provider and see what options that they may have available to you. If you are looking for a new hosting provider or your current provider cannot help, I would suggest that you take a look at the siteground hosting review page as this will give you honest opinions and reviews from real-world users which might tempt you to change your provider. While, on the other hand, if you’re interested to know what are some stable Siteground alternatives available, check out the referenced article on AlterWebHost.

But the way I am going to demonstrate is the way that I have setup all mine and my clients sites.

What Content Management System are you using?

The first thing you need to do is to identify what you are using as your content management system (CMS). For a large majority of blogs, WordPress has been the CMS platform of choice, it is also mine. This guide will walk through the steps needed to setup for a WordPress blog, however, if you are using another CMS platform and you are hosted on a Nginx or Apache server, then I would suggest you take a look at this guide from Kinsta that explains how to set that platforms up. It is more complicated though, so for this guide, I am going to go through the process using WordPress.

Cloudflare

NOTE: For Cloudflare to work, you have to redirect your nameservers to Cloudflare. This means if you want to make any DNS changes in the future, you do it in your Cloudflare portal, not through your hosting. If you are not happy with this, do not bother reading on!

The first thing you will need to carry out is to setup a free Cloudflare account. Cloudflare offer you a free service which includes free caching, free enhanced security again attacks on your site and what we are really here for, free SSL certificate for your site.

The sign up process is simple, just complete the registration form and you are in. Then you need to add your site to your Cloudflare account. To do this, at the top right of the screen you will see an Add site button:

Cloudflare add site
Click to enlarge

Type in your domain name and then click on the Add Site button:

Add your site to cloudflare
Click to enlarge

Then select the Free plan:

cloudflare free plan
Click to enlarge

Cloudflare will then pull through all your DNS entries for you, you should not have to make any changes here unless you want to. You can go ahead and click the Continue button.

You will now get to the part where you will be given the information to change your nameservers. All you need to do is to take note of the Cloudflare nameservers that they want you to change to:

cloudflare nameservers dns
Click to enlarge

Then email your host and ask them to change your domain nameservers to those provided by Cloudflare. Once you have made this request and your host has made this change, wait up to 48 hours for the change to propagate and login to your Cloudflare account. You should now see that the status is now Active:

cloudflare active
Click to enlarge

Applying the SSL Certificate (HTTP – HTTPS)

You can have a browse around the Cloudflare portal if you like and try out some new settings like Caching, Analytics and Apps, but for now, we are going to go into the Crypto section and change the SSL setting to Full:

cloudflare certificate crypto
Click to enlarge

Then on the same page, scroll down and change the following to be switched on:

  • Always use HTTPS
  • Automatic HTTPS Rewrites
automatic https rewrites
Click to enlarge
Cloudflare always use https
Click to enlarge

You then have to wait for around 24 hours for a certificate to be produced and then automatically applied to your site.

After that time, go to your site and you should now see that you have HTTPS setup. You should also noticed that even if your visitors go to your site using HTTP, that it will automatically redirect them to your HTTPS site.

Sanity Checking

There are a few things you should check once you have carried this out:

  • Are your images appearing correctly? – if not, install a WordPress plugin called Really Simple SSL and activate it – this should resolve any issues with hard links to your images or other little niggles you may have.
  • Is HTTP redirecting to HTTPS? – if not, check your Cloudflare portal and make sure the two features above are switched on.
  • Clear any caches that you may setup.

That is it, you should now have a fully functional site with HTTPS enabled. Google will love you and so will your visitors!

Feedback

If you have any questions or want to leave us some feedback on your experience, you can get us on our Social Media platforms or leave us a message below in the comments section.