How to Apply jQuery UI Datepicker in WordPress?

How to Apply jQuery UI Datepicker in WordPress?

Use jquery datepicker in wordpress

First write following simple wordpress source code in template file. These source code will include js as well as datepicker class in the template.

wp_enqueue_script('jquery');
wp_enqueue_script('jquery-ui-core');
wp_enqueue_script('jquery-ui-datepicker');
wp_enqueue_style('jquery-ui-css', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/themes/smoothness/jquery-ui.css');

Write following php source code in functions.php for date field. Or you can also write this source code in template file.

<!--?php function display_and_set_custom_date_picker(){ ?-->
<script type="text/javascript">
jQuery(document).ready(function(){
    jQuery('#birth_date').datepicker({
        dateFormat: 'dd-mm-yy'
    });
});
</script>
<!--?php
} 
// close display_and_set_custom_date_picker() here


//add an action to call display_and_set_custom_date_picker function
add_action('wp_footer','display_and_set_custom_date_picker',10);
</pre-->
<p>and last step to Add Id “birth_date” to input HTML field like below.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic"> <input id="birth_date" name="birth_date">
</pre>
<p>I hope you get an idea about <strong>wp custom field-date picker</strong>.<br>
I would like to have feedback on my <a href="https://infinityknow.com/" target="_blank" rel="noopener noreferrer">infinityknow.com blog</a>.<br>
Your valuable feedback, question, or comments about this article are always welcome.<br>
If you enjoyed and liked this post, don’t forget to share.</p>
<div class="yarpp yarpp-related yarpp-related-website yarpp-template-list">
<!-- YARPP List -->
<div class="addthis_inline_share_toolbox"></div> <h3>Related posts:</h3><ol>
<li><a href="https://www.pakainfo.com/datepicker-change-date-format-dynamically-using-jquery/" rel="bookmark" title="datepicker change date format dynamically using jquery">datepicker change date format dynamically using jquery</a></li>
<li><a href="https://www.pakainfo.com/wordpress-next-previous-article-post-using-css/" rel="bookmark" title="WordPress Next Previous Article/post using CSS">WordPress Next Previous Article/post using CSS</a></li>
<li><a href="https://www.pakainfo.com/multiple-image-slider-in-html-source-code/" rel="bookmark" title="Multiple image slider in html source code">Multiple image slider in html source code</a></li>
<li><a href="https://www.pakainfo.com/how-to-create-image-hover-overlay-effects/" rel="bookmark" title="How To Create Image Hover Overlay Effects?">How To Create Image Hover Overlay Effects?</a></li>
<li><a href="https://www.pakainfo.com/wordpress-pagination-example/" rel="bookmark" title="wordpress pagination example">wordpress pagination example</a></li>
</ol>
</div>
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments