How To Get Base, Media, Link Url In Magento2

How To Get Base, Media, Link Url In Magento2

To get the base URL, media URL, and link URL in Magento 2, you can use Magento’s built-in functions to retrieve these URLs programmatically. To get the base URL, use the following code:

$baseUrl = $this->_url->getBaseUrl();
For the media URL, which points to the media directory where files like images are stored, you can use:
$mediaUrl = $this->_mediaDirectory->getAbsolutePath('media');
To get a specific link URL for a page, product, or category, you can use:
$linkUrl = $this->_url->getUrl('path_to_resource');

You can access these values through the constructor by injecting the necessary dependencies, like \Magento\Framework\UrlInterface for the base URL and \Magento\MediaStorage\Model\File\Storage\Database for media URLs.

These methods provide a flexible and dynamic way to retrieve URLs based on your Magento 2 configuration.

How to Enable Template Path Hints in Magento 2

How to Enable Template Path Hints in Magento 2:

Go to Magento 2 admin panel and login with your credentials.
Go to Stores –> Configuration.
Select Developer option from the Advanced tab at the end.
Open Debug dropdown and set Enabled Template Path Hints for Storefront to yes.

Click to Save Config.

How to Change Magento 2 Logo

Here are the steps that you will follow to change Logo in Magento 2

Go to your Magento 2 admin.
Go to STORES > Configuration > Design > Header
Click Choose file and select your logo
Click Save Config

Get page id in wordpress

Here is the tips for getting page id in wordpress. First of all I will show page id in admin area.

Go to the pages and clcik on that, then you can see all pages list. Look the below screenhsot.

After then click on the desired page and you can see the page id on the address bar as I have marked. attached screenshot.

If you want to check page id on the front side then you should use the code. Use the blow wordpress function . It will give you the page id on the pages
get_the_ID();

More detail you can get here

If you want to show page id only for specific page then you can use the below code
<?php if(get_the_ID() == ‘475’) {?>
I am your page
<?php } ?>

Static blocks not working – Magento 1.9.x

After updating Magento to version 1.9.x, or installing security patch SUPEE-6788 on an older version, lots of people are noticing that their static block shortcodes are no longer working. So may be some developers frustrated or confused why this happen. The solution is simple magento people added security feature on the newer version.
Simply navigate to

System => Permissions => Blocks

And add the block type you wish to display.

Burger menu not working on ipad/tablet in wordpress

Burger menu not working on ipad/tablet in wordpress

If you are working with wordpress enfold theme then may be you get the issue of menu on the tablet/ipad in landscape mode. Them menu does not appears as a burger so try this media query, may be it will help :


@media only screen and (max-width: 1024px) { /*** put your css code here ****/}

 

How to change sign-up fee text in WooCommerce Subscriptions

How to change sign-up fee text in WooCommerce Subscriptions

Try this:

function change_subscription_product_string( $subscription_string, $product, $include )
{
if( $include['sign_up_fee'] ){
$subscription_string = str_replace('sign-up fee', 'your text', $subscription_string);
}
return $subscription_string;
}
add_filter( 'woocommerce_subscriptions_product_price_string', 'change_subscription_product_string', 10, 3 );

lessphp fatal error: load error! help in wordpress

If you’re encountering the LessPHP Fatal Error: Load Error! in WordPress, it typically means there is an issue with the LessPHP compiler failing to load a required file. This error is common in themes or plugins that use Less (a CSS preprocessor) to generate stylesheets dynamically. To resolve the issue, try the following steps:

1. Clear your cache – if your theme or plugin has a cache folder, delete its contents.

2. Check file permissions – ensure that your theme’s less and css folders have the correct read/write permissions (usually 755 for folders and 644 for files).

3. Reinstall or update the theme/plugin – a corrupted or outdated file may be causing the issue.

4. Disable conflicting plugins – if you recently installed or updated a plugin, try disabling it to see if the error goes away.

5. Enable debugging – add define('WP_DEBUG', true); in your wp-config.php file to get more details on the error. If the issue persists, consider reaching out to your theme or plugin developer for support.

Magento – Show Inventory Levels on Product Pages

Today I will show you how we can add Quantity on hand information on the product detail page.Normal Magento shows ‘Availability-In Stock’ by default. We need to change that Qty on hand like the below image

qtyonhand

For this you need to do the below steps :
Go to app/design/frontend/base/default/template/catalog/product/view/type/default.phtml.
Get a copy of that file and move it to your custom theme, making sure to add folders as needed to maintain the correct path. Here is the code snippet for adding Quantity on Hand to your product pages.

Replace below code

<?php if ($_product--->isAvailable()): ?>

with

<?php if ($_product--->isAvailable()): ?>
<?php $quantity1 = intval(Mage::getModel('cataloginventory/stock_item')--->loadByProduct($_product)->getQty()); ?>

<div class=”add-to-box”>

<?php if($quantity1 > 0) { ?>

<p class=”availability in-stock”>
<?php echo $this->__(‘Qty on Hand:’) ?>
<?php echo $quantity1;?>
</span>
</p>

<?php } elseif($quantity1 == 0) { ?>
<p class=”availability in-stock”><?php echo $this—>__(‘Qty on Hand:’) ?></p>
<?php foreach ($_product ->getTypeInstance(true)->getUsedProducts ( null, $_product) as $simple) { $stock = intval(Mage::getModel(‘cataloginventory/stock_item’)->loadByProduct($simple)->getQty()); echo $simple->getName().” “.$simple->getSize().” have a stock of $stock”; echo ‘<br>’; } ?>
</p>
<?php } ?>
</div>

How to change the Magento Admin URL

Here is a quick guide on how to change admin url path in Magento. To protect your Magento backend against hackers and brute-force attacks, we recommend that you change the default URL to the Magento Admin Panel is must. It is a quick and easy way to add an extra layer of security to your site.

Generally, Magento have ‘admin’ as the administrator path. So, the admin URL will be http://www.example.com/admin/

Here is process how you can do this :

1) Changing local.xml
– Open app/etc/local.xml
– Find the following:-

<admin>
<routers>
<adminhtml>
<args>
<frontName><![CDATA[admin]]></frontName>
</args>
</adminhtml>
</routers>
</admin>

– Go to this line
<frontName><![CDATA[admin]]></frontName>

and change “admin” as you desired the admin path like

<frontName><![CDATA[siteadmin]]></frontName>

and then upload file. After file update clear magento cache.

The process is now complete and you can login your magento with new url path

http://www.example.com/siteadmin/