Category Archives: PHP

What is My WordPress Site’s Login URL

I just installed WordPress script on my hosting, but I dont know the admin login URL of WordPress

Typically, you can access login page via the following URLs

  • http://www.example.com/login/
  • http://www.example.com/admin/

However if permalink  or seo friendly URL is not working, you can access login page via the following URL

  • http://www.example.com/wp-login.php
If  your WordPress was installed in a sub-folder such as /wp/

You can access login URL  via the following URLs

  • http://www.example.com/wp/login/
  • http://www.example.com/wp/wp-login.php
If your WordPress was installed on a sub-domain

You can access login URL via the following URLs

  • http://sub-domain.example.com/login/
  • http://sub-domain.example.com/wp-login.php

How Can I Disable All Magento 2 Extensions

I would like to disable all extensions, what is the simplest way for Magento 2

You can use one command line to disabled all Magento 2 extensions or custom modules

php bin/magento module:status | grep -v Magento | grep -v List | grep -v None | grep -v -e ‘^$’| xargs php bin/magento module:disable

Enable all extensions or modules

php bin/magento module:status | grep -v Magento | grep -v List | grep -v None | grep -v -e ‘^$’| xargs php bin/magento module:enable

How to Active Magento 2 Category Programmatically

How can I active a Magento 2 category programmatically based on given category ID

After load Magento 2 category object, you can use setIsActive method to active or inactive the category.

$catid = 1;
$storeid = 1;
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$categoryRepository = $objectManager->get(‘MagentoCatalogModelCategoryRepository’);
$category = $categoryRepository->get($catid , $storeid);
$category->setIsActive(true);
$categoryRepository->save($category);

How To get Current Magento 2 Customer ID

How to get current Magento 2 customer id programmatically after logged in.

You can use “\Magento\Customer\Model\Session ” to retrieve the current customer session and use it to get customer id.

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$customerSession = $objectManager->get(‘\Magento\Customer\Model\Session’);
$custom_id =  $customerSession->getCustomer()->getId();

How Can I Know the Current Page is Magento 2 CMS Page

How can I know the current page is CMS page from Magento 2 Block class

You can use “\Magento\Framework\App\Request\Http” to retrieve the current request and use it to find out which module.

$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $request = $objectManager->get(‘\Magento\Framework\App\Request\Http’); $checkModule = $request->getModuleName();
if($checkModule == ‘cms’){
echo “cms page”;
}else{
echo “not cms page”;
}

How to get Magento 2 Product’s Image URL Programmatically

How can I retrieve Magento 2 product’s image URL from published/cache frontend.

After get Magento 2 product’s image url, you need to use “\Magento\Catalog\Helper\Image” to generate a public image url.

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$helperImport = $objectManager->get(‘\Magento\Catalog\Helper\Image’);
$registry = $objectManager->get(‘\Magento\Framework\Registry’);
$product = $registry->registry(‘current_product’);
$imageUrl = $helperImport->init($product, ‘product_page_image_small’) ->setImageFile($product->getSmallImage())->getUrl();

How To Get Current Magento 2 Category Name Programmatically

How to get current Magento 2 category name from Block class

To retrieve current Magento 2 category name from Block class, you need load “Magento\Framework\Registry” object first and then call “registry(‘current_category’)” method to get current category object. Here is the example.

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$registry = $objectManager->get(‘\Magento\Framework\Registry’);
$category = $registry->registry(‘current_category’);
$categoryName = $category->getName();

How To Get Current Magento 2 Product Info Programmatically

How to get current Magento 2 product info programmatically from Block class

You can use “Magento\Framework\Registry ” to retrieve current magento 2 product object.

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$registry = $objectManager->get(‘\Magento\Framework\Registry’);
$product = $registry->registry(‘current_product’);

Get product’s name

$productName = $product->getName();

Get product’s sku

$productName = $product->getSku();

Get product’s ID

$productName = $product->getId();