Categories
Uncategorized

How to remove required attribute from text field with jquery?

 Remove required attribute from text field with jquery

$(‘#enterpassword’).removeAttr(‘required’);

$(“#enternumber”).removeAttr(‘disabled’);


Categories
Uncategorized

How to get all months in php?

Get all months in php                            
for ($m=1; $m<=12; $m++) 
{
$month = date(‘F’, mktime(0,0,0,$m, 1, date(‘Y’)));
                                     echo $month;
                               }
Categories
Uncategorized

How to get all unique years from a date column using Sql(Mysql)?

 Get all unique years from a date column using Sql(Mysql)?

SELECT distinct year(OrderDate) FROM Orders;

SELECT distinct year(column_name) FROM table_name;

Categories
Uncategorized

How to get previews years from current year in php?


Get previews years from current year in php

<?php
echo date(“Y”,strtotime(“-1 year”));
 ?>

Categories
Uncategorized

How to redirect after login (login_redirect) based on user role in wordpress?

Redirect after login (login_redirect) based on user role in wordpress

function my_login_redirect( $redirect_to, $request, $user ) {
    //is there a user to check?
    global $user;
    if ( isset( $user->roles ) && is_array( $user->roles ) ) {
        //check for admins
        if ( in_array( ‘administrator’, $user->roles ) ) {
            // redirect them to the default place
            return $redirect_to;
        } else {
            return home_url(‘/my-profile/’);
        }
    } else {
        return $redirect_to;
    }
}

add_filter( ‘login_redirect’, ‘my_login_redirect’, 10, 3 );

Categories
Uncategorized

How to Create a Custom Page in WordPress?

<?php /* Template Name: myfirstpage */ ?>
 
<?php get_header(); ?>
 
<div id="primary" class="content-area">
    <main id="main" class="site-main" role="main">
        <?php
        // Start the loop.
        while ( have_posts() ) : the_post();
 
            // Include the page content template.
            get_template_part( 'template-parts/content', 'page' );
 
            // If comments are open or we have at least one comment, load up the comment template.
            if ( comments_open() || get_comments_number() ) {
                comments_template();
            }
 
            // End of the loop.
        endwhile;
        ?>
 
    </main><!-- .site-main -->
 
    <?php get_sidebar( 'content-bottom' ); ?>
 
</div><!-- .content-area -->
 
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Categories
Uncategorized

How do you round to 1 decimal place in Javascript (roundup)?

Round to 1 decimal place in Javascript (roundup)

var number = 12.3456789;
var rounded = Math.round( number * 10 ) / 10;
// rounded is 12.3

Categories
Uncategorized

how to remove value after decimal in javascript?

Remove value after decimal in javascript

<!DOCTYPE html>
<html>
<body>
<p>Value:</p>
<script>
var myFloat = 4.5;
var myTrunc = Math.trunc( myFloat );
document.write(myTrunc+ ” “);
</script>
</body>
</html>

Categories
Uncategorized

How to use inner html value or data in php from javascript(innerHTML)?

 use inner html value or data in php from javascript(innerHTML)?

<html>
<body>

<p id=”demo”>use inner html value in php(innerhtml)</p>

<script>

  var jassi = document.getElementById(“demo”).innerHTML;
  //document.write(jassi);

</script>

<?php
$jassi = ‘<script>document.write(jassi);</script>’;
echo $jassi;

?>
</body>
</html>

Categories
Uncategorized

How to get current user info from wp user database in wordpress?

 Get current user info from wp user database in wordpress

<?php global $current_user;
get_currentuserinfo();

echo ‘Username: ‘ . $current_user->user_login . “n”;
echo ‘User email: ‘ . $current_user->user_email . “n”;
echo ‘User level: ‘ . $current_user->user_level . “n”;
echo ‘User first name: ‘ . $current_user->user_firstname . “n”;
echo ‘User last name: ‘ . $current_user->user_lastname . “n”;
echo ‘User display name: ‘ . $current_user->display_name . “n”;
echo ‘User ID: ‘ . $current_user->ID . “n”;
?>