Wednesday 20 April 2022

How to Removing product _ product-category _ or shop from the URLs in WordPress, WooCommerce?

Here, Removing /product/, /product-category/, or /shop/ from the URLs is not advisable due to the way WordPress resolves its URLs. It uses the product-category (or any other text for that matter) base of an URL to detect that it is an URL leading to a product category.

There are SEO plugins that allow you to remove this base, but that can lead to a number of problems with performance and duplicate URLs.


Try following Plugins:-
1> Remove slug from custom post type
https://wordpress.org/support/plugin/remove-slug-from-custom-post-type
Just install & activate this plugin/remove-slug-from-custom-post-type

2> SEO Ultimate
https://wordpress.org/plugins/seo-ultimate/
In SEO Ultimate settings under 'Permalink Tweaker' check the 'Product Categories' and save.


For more Interesting, Useful Article & codes visit IT New Code.

On logged in user can view WP site? How to Make Member only site?

Add following code in theme "functions.php"  file




/*************************************************************************************************************
 * Only logged in user can view site except Login, Register, Password-Recovery & successful Registration pages
 *************************************************************************************************************/
add_action( 'wp', 'members_only' );
function members_only() {
    // Restrict unlogged user
    if( !is_user_logged_in() ) {
        // id specified page then execute
        // 789 is page id for "Registration" page.
        // 792 is page id for "Login" page is also Home page.
        // 796 is page id for "Password Recovery" page.
        // 868 is page id for "Successful Registration" page.
        // is_front_page() for website main page.
        if (is_page(789) || is_page(792) || is_page(796) || is_page(868) || is_front_page() ) {
           // echo "This is current page";
        }
        else {
            // Redirect to Home page.
            //wp_redirect( get_home_url() );
            wp_redirect( 'https://www.example.com/wp-login.php' );
            exit;
        }
    }
}

How to Disable copy & Paste on website?

Just put following code in Header section <head> tag.


<!----- Put this code in "<head>" tag   ------>

<script type="text/javascript" language="javascript">

     $(function() {

            $(this).bind("contextmenu", function(e) {

                e.preventDefault();

            });

        });
</script>
<script type="text/JavaScript">
function killCopy(e){ return false }
function reEnable(){ return true }
document.onselectstart=new Function ("return false");
if (window.sidebar)
{ document.onmousedown=killCopy;
document.onclick=reEnable; }
</script>


For more Interesting, Useful Article & codes visit IT New Code.

How to Disable Right click on website?

Just put following code in Header section <head> tag.


<!----- Put this code in "<head>" tag   ------>

<script language="javascript">

                   var message="This function is not allowed here.";
                   function clickIE4(){

                                 if (event.button==2){
                                 alert(message);
                                 return false;
                                 }
                   }

                   function clickNS4(e){
                                 if (document.layers||document.getElementById&&!document.all){
                                                if (e.which==2||e.which==3){
                                                          alert(message);
                                                          return false;
                                                }
                                        }
                   }

                   if (document.layers){
                                 document.captureEvents(Event.MOUSEDOWN);
                                 document.onmousedown=clickNS4;
                   }

                   else if (document.all&&!document.getElementById){
                                 document.onmousedown=clickIE4;
                   }

                   document.oncontextmenu=new Function("alert(message);return false;")

    </script>


For more Interesting, Useful Article & codes visit IT New Code.

How to create a map based on Latitude & Longitude?

Sometimes we need a map based on specified location or dynamically create a map. Then we need to use Latitude & Longitude. Latitude & Longitude provide the perfect location of any place. By finding that we can create a map using it.

Below Gives full code of Creation of map base on Latitude & Longitude.

<html>
<head>
<style type="text/css">
            div#map {
width: 100%;
height: 200px;
            }
</style>

<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
        <script type="text/javascript">
            var map;
            var geocoder;
            var centerChangedLast;
            var reverseGeocodedLast;
            var currentReverseGeocodeResponse;

            function initialize() {
                var latlng = new google.maps.LatLng(-41.2785537,174.778663);
/*FOR PHP CODE:  var latlng = new google.maps.LatLng("<?php echo $is_about_physical_address_lat; ?>","<?php echo $is_about_physical_address_lng; ?>");  */
                var myOptions = {
                    zoom: 14,
                    center: latlng,
                    mapTypeId: google.maps.MapTypeId.ROADMAP
                };
                map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
                geocoder = new google.maps.Geocoder();

                var marker = new google.maps.Marker({
                    position: latlng,
                    map: map,
                    title: "Hello World!"
   /*FOR PHP CODE:  title: "<?php echo $is_about_postal_address; ?>, <?php echo $is_about_country_name; ?>"  */
                });

            }
</script>
</head>

<body onLoad="initialize()">
        <div id="map">
            <div id="map_canvas" style="width:100%; height:200px"></div>
            <div id="maparea"></div>
        </div>
</body>
</html>






For more Interesting, Useful Article & codes visit IT New Code.

How to generate random number?

Using following code we can create random number. Than can be use Order number, unique id or like something that.

<?php 

//Unique or Random number Generate
//$today = date("Ymd");
$today = date("dmY");
$random = strtoupper(substr(uniqid(sha1(time())),0,6));
echo $order_no = $today . $random;

?>


For more Interesting, Useful Article & codes visit IT New Code.

How to get IP Address of System?

Run following PHP code for get IP Address.




<html>
<head>
 <title>What is my IP address?</title>
</head>
<body>
<?php
  $ipaddress = '';
    if ($_SERVER['HTTP_CLIENT_IP']){
        echo "1-Ip is:".$ipaddress = $_SERVER['HTTP_CLIENT_IP'];
    }
    else if($_SERVER['HTTP_X_FORWARDED_FOR']){
        echo "2-Ip is:".$ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
}
    else if($_SERVER['HTTP_X_FORWARDED']){
        echo "3-Ip is:".$ipaddress = $_SERVER['HTTP_X_FORWARDED'];
}     else if($_SERVER['HTTP_FORWARDED_FOR']){
        echo "4-Ip is:".$ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];
}     else if($_SERVER['HTTP_FORWARDED']){
        echo "5-Ip is:".$ipaddress = $_SERVER['HTTP_FORWARDED'];
}     else if($_SERVER['REMOTE_ADDR']){
        echo "6-Ip is:".$ipaddress = $_SERVER['REMOTE_ADDR'];
}     else{
        echo "7-Ip is:".$ipaddress = 'UNKNOWN';
}
?>
</body>
</html>






For more Interesting, Useful Article & codes visit IT New Code.

 

Copyright @ 2016 IT New Code | Developing Code | Designing Code.

Designed by: Ankit Shah