WordPress: get author info / user details from post id

Some times we needed to pull out the author data from a post id. It is very easy do it in wordpress.

It can be accomplished by the_author_meta() function or get_the_author_meta() function. You will need call this function in your theme or plugin, through a hook.

the_author_meta() –> Outputs the data, just like echo
get_the_author_meta() -> holds the value in value.

We can get the data like this :

 

$auth = get_post($post_ID); // gets author from post
$authid = $auth->post_author; // gets author id for the post
$user_email = get_the_author_meta('user_email',$authid); // retrieve user email
$user_firstname = get_the_author_meta('user_firstname',$authid); // retrieve firstname
$user_nickname = get_the_author_meta('nickname,$authid); // retrieve user nickname

The following list of user fields you can retrieve using this function.

  • user_login
  • user_pass
  • user_nicename
  • user_email
  • user_url
  • user_registered
  • user_activation_key
  • user_status
  • display_name
  • nickname
  • first_name
  • last_name
  • description
  • jabber
  • aim
  • yim
  • user_level
  • user_firstname
  • user_lastname
  • user_description
  • rich_editing
  • comment_shortcuts
  • admin_color
  • plugins_per_page
  • plugins_last_view
  • ID

 

Get Google To Remove The Blacklist Warning

After fully cleaning up your site infection, you must inform Google to remove the blacklist warning. To do this, you must have a Google Search Console account (formerly Webmaster Tools). This way, the malware warning can quickly be removed.

To verify ownership of your website in Google Search Console:

  1. Open Google Webmaster Central.
  2. Click Search Console and sign in with your Google account.
  3. Click Add a site.
  4. Type in your site’s URL and click Continue.
  5. Verify your site using the Recommended method or Alternate methods options.
  6. Click Add a site.
  7. Click Verify.
  8. Check the Messages section to review any warnings.

CORS policy: No ‘Access-Control-Allow-Origin’

Font from origin domain.dev has been blocked… (CORS and browsersync)

If you are getting issue fonts are blocked in web client CORS then below code will help you. Use the code in .htaccess file and problem will be resolved 🙂
# Allow access from all domains for webfonts.
<IfModule mod_headers.c>
<FilesMatch “\.(ttf|ttc|otf|eot|woff|woff2|font.css|css)$”>
Header set Access-Control-Allow-Origin “*”
</FilesMatch>
</IfModule>

How to use WordPress Shortcode in template

Shortcodes in WordPress are little bits of code that allow you to do various things with little effort. You can use in the content area to invoke some kind of function to accomplish certain tasks.

But what if you want to use a shortcode from within a template instead of with the content of a Post/Page? You can invoke it with a special function:

<?php echo do_shortcode("[shortcode]"); ?>

Web Setup Wizard 401 Unauthorised Access

Today I got issue on Magento2 site when try to open Web Setup Wizard section.

System -> Tools -> Web Setup Wizard

Here is the solution for fixing this issue. This one works for me so I thought it would be just posted for all of the world 🙂

You have change some settings as per below.

Goto Stores -> Configuration – > General -> Web

Base URLs (Secure)
-> Use Secure URLs on Storefront -> Yes
-> Use Secure URLs in Admin -> Yes
-> Enable HTTP Strict Transport Security (HSTS) -> Yes
-> Upgrade Insecure Requests -> Yes

and then run the below command
php bin/magento cache:clean

What is WordPress Permalink

WordPress offers you the ability to create a custom URL structure for your permalinks and archives. Custom URL structures can improve the aesthetics, usability, and forward-compatibility of your links.

Permalinks are the permanent URLs of your individual blog post or page on your WordPress site. Permalinks are also referred to as pretty links. By default, WordPress URLs use the query string format which look something like this:

http://www.example.com/?p=123

  • where “123” is the ID of a given post or page in the database.

To set permalinks in WordPress

There are two way to set permalinks on the Wordrpess sites:

  1. You need to set the permalink structure right after you launch a new WordPress site.
  2. You should set the permalinks for every piece of content individually.

1. How to set the permalink structure in WordPress

There are various different formats that you can use. Day and name, Month and name, Numeric, Post name, and Custom structure. Any format that is not the default one is SEO friendly. It just comes down to your preference after that.

Go to Settings » Permalinks option page,  Once there, select this option:

  • Just to make sure we’re on the same page, it’s the one labeled “Post name.”

Now, why this one?

Quite simply, it holds the least amount of unneeded clutter… There are no seemingly random numbers, no dates, no arbitrary words (like “archives”). There’s just the post name that you can control 100% (more on that in the next point).

Note. Why you don’t want dates in your permalinks? The main reason is because dates discourage your visitors from reading your older content. Any date that’s older than last week (or so) looks like out-of-date information, despite the fact that it might still be very valid, or might even be evergreen.

After you select that new permalink structure (“Post name”), just click “Save Changes” at the bottom of the settings page.

2. How to set the individual permalinks for posts/pages

You can update permalink directly on the each individual posts or pages. For example you see here

 

Click on the edit and you can update anything…..

Oh, Finally update the page 🙂 and you’r done!!

How to enable maintenance mode in Magento

This article describes how to enable maintenance mode in Magento. When Magento is in maintenance mode, visitors see a Service Temporarily Unavailable message in their web browsers instead of the store. However, authorized IP addresses can still view the store normally.

This feature allows you to develop and test your store before it goes “live,” or do other maintenance tasks, such as installing updates.

To set Magento in maintenance mode you need to create a file with name “maintenance.flag” and drop it to Magento home directory. While this file exists your website visitors will see a temporary page (/errors/503.php). If you want to edit this page content you can find it in Magento admin – CMS/Pages, it is called “503 Service Unavailable”.

Once you finished with changes and your website is ready to work just delete maintenance.flag file and maintenance mode will be off, so your Magento website will work as usual.

All we need to do it edit 3 lines.

Open: index.php in root and above line 57 add (remembering to edit the ‘allowed’ array to contain the IP’s you want to be able to access the site);

$ip = $_SERVER['REMOTE_ADDR'];
$allowed = array('1.1.1.1','2.2.2.2'); // these are the IP's that are allowed to view the site.

then change the line
if (file_exists($maintenanceFile)) {
to
if (file_exists($maintenanceFile) && !in_array($ip, $allowed)) {

Simple. Now you can access the site, while others see its maintenance mode.

Know android codes for mobile device

Know android codes for mobile device :

1- For IMEI NUMBER :

*#06#

2- for Ram

*#*#3264#*#*

3- Phone service menu

*#0*#

4- Battery Status

*#0228#

5- phone service mode

*#9090#

6- Battery use or device related information

*#*#4636#*#*

7- Camera related inforamtion

*#*#34971539#*#*

8 – Software/Hardware information

*#12580*369#

Fix 404 error in WordPress category / tag page

Sometimes, especially after switching themes, WordPress will generate 404 errors on the category and tag pages. There might be multiple reasons – and also multiple solutions – to this, here is simple solution and it will fix the issue

Go to your WordPress backend, click Settings, click Permalinks. Make sure the category base is “category” and the tag base is “tag” (unless you have some VERY weird special settings) and simply press the “save changes” button. Even if nothing has changed, clicking the button will probably make your category and tag pages work again now.

Oh, Finally Don’t forget to clear the cache…. 🙂

 

Fix wordpress post 404 error

WordPress is fantastic CMS. Most of the world love it feature and flexibility. I am always try to recommend my clients to use this. Sometimes wordpress users face common problems and one of them in posts 404 error. Today we will learn how we can fix this issue.

This is the simple setting we can do fix this issue easy way.

Go to Settings » Permalinks, and simply click on Save Changes button. This will update your permalinks settings and flush rewrite rules. In most cases this solution fixes theWordPress posts 404 error. However, if it does not work for you, then you probably need to update your .htaccess file manually.

Login to your server using FTP, and modify the .htaccess file which is located in root folder. The easiest thing you can do is to temporarily make the file writeable by changing the permissions to 644.  You can should manually add this code if that is not alreay in in .htaccess file. If .htaccess file not available then you must upload this file.

# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress