We provide knowledgeable blogs related to php, jQuery, html, css, wordpress, woocommerce, cordova app with examples in 2021.
31 December 2019
30 November 2019
How to remove required attribute from text field with jquery?
Remove required attribute from text field with jquery
$('#enterpassword').removeAttr('required');
$("#enternumber").removeAttr('disabled');
$("#enternumber").removeAttr('disabled');
28 November 2019
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;
}
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;
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"));
?>
25 November 2019
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 );
13 November 2019
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(); ?>
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
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>
12 November 2019
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>
09 November 2019
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";
?>
How to redirect on any page in wordpress in php?
Redirect on any page in wordpress in php
wp_redirect(site_url().’/page-name/‘);
How to redirect on any specific page after woocommerce login?
Redirect on any specific page after woocommerce login
function admin_default_page() {
return '/new-dashboard-url';
}
add_filter('login_redirect', 'admin_default_page');
02 November 2019
Add business days to specific date in php
echo date('d-m-Y', strtotime( $specificdate . " +$businessdays weekdays") );
Calculate business days between two dates (working weekdays between two dates)
$startdate = "5-11-2019";
$enddate = "17-11-2019"
$businessdays = number_of_working_days($startdate, $enddate);
echo $businessdays;
function number_of_working_days($from, $to) {
$workingDays = [1, 2, 3, 4, 5]; # date format = N (1 = Monday, ...)
$from = new DateTime($from);
$to = new DateTime($to);
$to->modify('+1 day');
$interval = new DateInterval('P1D');
$periods = new DatePeriod($from, $interval, $to);
$days = 0;
foreach ($periods as $period) {
if (!in_array($period->format('N'), $workingDays)) continue;
$days++;
}
return $days;
}
$enddate = "17-11-2019"
$businessdays = number_of_working_days($startdate, $enddate);
echo $businessdays;
function number_of_working_days($from, $to) {
$workingDays = [1, 2, 3, 4, 5]; # date format = N (1 = Monday, ...)
$from = new DateTime($from);
$to = new DateTime($to);
$to->modify('+1 day');
$interval = new DateInterval('P1D');
$periods = new DatePeriod($from, $interval, $to);
$days = 0;
foreach ($periods as $period) {
if (!in_array($period->format('N'), $workingDays)) continue;
$days++;
}
return $days;
}
How to add days in a specific date in php?
add days in a date in php
<?php
$Date = "2010-09-17";
echo date('Y-m-d', strtotime($Date. ' + 1 days'));
echo date('Y-m-d', strtotime($Date. ' + 2 days'));
?>
Subscribe to:
Posts (Atom)
How to add re-captcha v3 on all Elementor forms using coding?
Add re-captcha v3 on all Elementor forms using coding add_action('wp_footer',function(){ ?> <script src="https://www...
-
Preview doc or docx file in html/iFrame var link = "paste docx file link here"; var iFrameUrl = 'https://view.officeapps.live....
-
Detect the current user has an active subscription in Woocommerce. function has_active_subscription( $user_id=null ) { // When a...
-
Add re-captcha v3 on all Elementor forms using coding add_action('wp_footer',function(){ ?> <script src="https://www...