Nice!
I tried to insert the code in the wp-config.php file but it still doesn’t work… I mean both http and https work fine but I only want the https to work.
The code I provided works only for the yoursite.com/wp-admin
area. Which is the Wordpress dashboard, with this option, Wordpress forces all access on the dashboard to use https (redirecting all requests), so it shouldn’t run on http even if you put http on the browser. But it doesn’t change the general access to your site (like someone accessing your home page).
So maybe it’s because I didn’t submit my http and https site to the google search console?
No, Search Console don’t change how your site is accessed, it only changes how it appears on Google. If your site can be accessed through HTTP and HTTPS, and you register the Search Console account with “http://yoursite.com”, Google will index the http version of it. But if you registered like “https://yoursite.com” Google will register the https version, simple as that. You can even have both (but its not advisable).
Even if you register with http, but your site redirects all requests to https, Google will probably index your site with https, because GoogleBot will be redirected to https as well…
Did you try to put the HTTPS redirects on nginx? The best code for that is provided in one of the articles I sent you. This is very important, since it will redirect all access to https automatically.