Showing posts with label WordPress. Show all posts
Showing posts with label WordPress. Show all posts

Tuesday, 21 August 2018

Continue Shopping To Redirect Category Page Woocommerce


There is no functionality provide WooCommerce to retrieve last category page viewed. But, I solved.

First create a custom action, check if page is category page, and set Cat ID to session data if so. Then on your button, use this to get proper URL.

add_action( 'init', 'wp_check_product_cat_sess');
function wp_check_product_cat_sess(){
    if(!session_id()){
        session_start();
    }
}
add_action( 'wp', 'check_product_cats');
function check_product_cats(){
    global $wp_query;
    if( is_product_category() ){
        $_SESSION['set_last_cat_id'] = $wp_query->get_queried_object()->term_id;
    }
    if( is_product() ){
        $get_cats = get_the_terms( $wp_query->get_queried_object(), 'product_cat' ) ;
        if( count( $get_cats ) > 0 ){
            foreach($get_cats as $one_cat ){
                    $_SESSION['set_last_cat_id'] = $one_cat->term_id;
            }
        }
    }  
    if( is_cart()){
        //var_dump( $_SESSION['set_last_cat_id'] );
    }
}
add_filter( 'woocommerce_continue_shopping_redirect', 'woo_add_continue_shop_btn_to_cart', 20 );
function woo_add_continue_shop_btn_to_cart($return_to){
    if( isset( $_SESSION['set_last_cat_id'] ) ){
        $redirect_page_url = get_term_link( $_SESSION['set_last_cat_id'], 'product_cat' );
    }else{
        $redirect_page_url = get_permalink( wc_get_page_id( 'shop' ) );
    }
    return $redirect_page_url;
}

-------------------------------------------------
Let me know your thoughts and questions in the comments.
Email: vyasankit2008@gmail.com

Monday, 20 August 2018

Response video embeds in WordPress


 <?php
//Add Response code to video embeds in WordPress
function full_width_embed_html( $html ){
  return '<div class="video-container">' . $html . '</div>';
}
add_filter( 'embed_oembed_html', 'full_width_embed_html', 10, 3 );
add_filter( 'video_embed_html', 'full_width_embed_html' );
?>
<style>
.video-container {
  position: relative;
  padding-bottom: 56.25%;
  height: 0;
  overflow: hidden;
  max-width: 1200px;
  margin: 0 auto;
}
 
.video-container iframe, .video-container object, .video-container embed, .video-container video {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  width: 100%;
  height: 100%;
}
</style>


-------------------------------------------------
Let me know your thoughts and questions in the comments.
Email: vyasankit2008@gmail.com

Thursday, 2 August 2018

Wordpress Interview Questions Answers



1. What is WordPress?
ans. WordPress is free open source content management system (CMS) written PHP language. It allows users to create dynamic websites from personal blogs to e-commerce.Wordpress current stable version 4.9.7 as on July @018.

2. What year was WordPress released?
ans. 2003

3. minimum requirements to run WordPress.
ans.  PHP version 7.2 or greater. MySQL version 5.6 or greater OR MariaDB version 10.0 or greater.

4. Where is WordPress content stored?
ans. MySQL database on Server.

5. differences between Posts and Pages?
ans. Posts and Pages are the two content types in WP.
     1.Posts are timed and listed in chronological order with the latest posts at the top. Posts are meant to be shared and commented on.
     2. Pages are static are static content, so an about us, contact us page etc. They are permanent and timeless entries.

6. types of hooks in WP.
ans. two types hooks are available in WordPress, action hooks and filter hooks, modify areas in a theme or plugin without modifying the original file.

7. action hook.
ans. An Action hook in WordPress is a hook that is triggered at a specific time when WordPress is running and lets you take an action. This can include things like creating a widget when WordPress is initializing or sending a Tweet when someone publishes a post.
list of some Action hooks functions.
        has_action()
        add_action()
        do_action()
        do_action_ref_array()
        did_action()
        remove_action()
        remove_all_actions()
        doing_action()

8. filter hook.
ans. A Filter hook in WordPress allows you get and modify WordPress data before it is sent to the database or the browser. Some examples of filters would include customizing how excerpts are displayed or adding some custom code to the end of a blog post or headings.
               
    example of add_filter
    add_filter('the_content', 'hello_world');
    function hello_world($content){
        return $content . "<h1> Hello World </h1>";
    }

      list of some Filter hooks functions.
        has_filter()
        add_filter()
        apply_filters()
        apply_filters_ref_array()
        current_filter()
        remove_filter()
        remove_all_filters()
        doing_filter()

9. WordPress taxonomy.
ans. In WordPress, a “taxonomy” is a grouping mechanism for some posts (or links or custom post types).There are four default taxonomies in WordPress they are
        Category
        Tag
        Link Category
        Post Formats
        You are also free to create your custom taxonomies too.
   
10. default tables are the WordPress. - WordPress Tables 12.
ans. wp_commentmeta, wp_comments, wp_links, wp_options, wp_postmeta, wp_posts, wp_terms, wp_termmeta, wp_term_relationships, wp_term_taxonomy, wp_usermeta, wp_users.

11. How to run database Query on WordPress?
ans. <?php $wpdb->query('query'); ?> , other wpdb functions above such as get_results, get_var, get_row or get_col.

12. General tags - general-template tags
ans. 
     A template tag is code that instructs WordPress to “do” or “get” something. Like in header.php  we will use the tag bloginfo(‘name’) to get “Site Title” from wp-options table which is set in Setting > General at WordPress dashboard.
   
    The the_title() template tag is used to display the post title.
   
    wp_list_cats() is  for display categories.
   
    get_header() for getting header.
   
    get_sidebar() for display the sidebar on page.
   
    get_footer() for get the footer content on page.
           
    get_template_part()
    get_search_form()
    wp_loginout()
    wp_logout_url()
    wp_login_url()
    wp_login_form()
    wp_lostpassword_url()
    wp_register()
    wp_meta()
    get_bloginfo()
    get_current_blog_id()
    wp_title()
    single_post_title()
    wp_enqueue_script()
    get_the_author()
    wp_list_authors()
    category_description()
   
13. Does WordPress use cookies?
ans. Yes, WordPress has cookies and uses them for verification purpose of the users while they log in.

14. Which is the considerably best multilingual plugin in WordPress?
ans. WPML is the best multilingual plugin for WordPress.

15. write the short code in WordPress php file?
ans. <?php do_shortcode("[shortcode]"); ?>

16. In which cases you don’t see plugin menu?
ans. You can’t see your plugin menu when the blog is hosted on free wordpress.com as you cannot add plugin there.  Also, if you do not have an account of an administrator level on your WordPress dashboard, it is not possible to see plugin.

17. difference between the wp_title and the_title tags?
ans. wp_title() function is for use outside “The Loop” to display the title of a Page.  the_title() on the other hand is used within “The Loop“.

18. How to Create Custom Post Type?
ans. // Our custom post type function
    function create_posttype() {    
        register_post_type( 'movies',
        // CPT Options
            array(
                'labels' => array(
                    'name' => __( 'Movies' ),
                    'singular_name' => __( 'Movie' )
                ),
                'public' => true,
                'has_archive' => true,
                'rewrite' => array('slug' => 'movies'),
            )
        );
    }
    // Hooking up our function to theme setup
    add_action( 'init', 'create_posttype' );
   
19. check if a page exists by url?
ans. You can use get_page_by_path() function.

20. create mailchimp or vertical response campaign for newsletter subscribers & link with WordPress ?
ans. First Create List & Campaign on mailchimp/ WordPress account . Then subscribe users from WordPress in mailchimp list by plugin or  manual hard code webform.

21. How will you retrieve adjacent posts (next/previous) within the same category?
ans. We can retrieve previous post using get_adjacent_post() function and providing it ‘true‘ and taxonomy name in first and last parameters respectively. Setting third parameter to false will bring next adjacent post in front of you.

22. Activate Plugins via Code?
ans.       
                function plugin_activation( $plugin ) {
        if( ! function_exists('activate_plugin') ) {
            require_once ABSPATH . 'wp-admin/includes/plugin.php';
        }   
        if( ! is_plugin_active( $plugin ) ) {
            activate_plugin( $plugin );
        }
    }   
    plugin_activation('akismet/akismet.php');
       
23. How to Link External jQuery/Javascript files with WordPress
ans. Add your own scripts via wp_enqueue_script() in your template’s functions.php, appropriately setting dependences on jQuery, and wp_head() will add the scripts for you.

24.  How to retrieve an image attachment’s alt text?
ans. The wp_get_attachment_image() function which will return an HTML string containing these attributes:
    ‘src‘
    ‘class‘
    ‘alt‘
    ‘title‘.

25. inner join query :
    SELECT Orders.OrderID, Customers.CustomerName FROM Orders
    INNER JOIN Customers ON Orders.CustomerID=Customers.CustomerID;

26. SQL GROUP BY query :
                SELECT COUNT(CustomerID), Country FROM Customers
    GROUP BY Country ORDER BY COUNT(CustomerID) DESC;

27. wordpress plugins : conatc form 7, meta slider, ninja form, revolution slider, yost seo, buddypress, wp super cache, wordfance.

28. get sidebar by id name : <?php dynamic_sidebar( 'left-sidebar' ); ?>

29. Add a WordPress Widget :
ans.
    function wpb_widgets_init() {    
        register_sidebar( array(
            'name'          => 'Custom Header Widget Area',
            'id'            => 'custom-header-widget',
            'before_widget' => '<div class="chw-widget">',
            'after_widget'  => '</div>',
            'before_title'  => '<h2 class="chw-title">',
            'after_title'   => '</h2>',
        ) );    
    }
    add_action( 'widgets_init', 'wpb_widgets_init' );

-------------------------------------------------
Let me know your thoughts and questions in the comments.
Email: vyasankit2008@gmail.com

Saturday, 21 July 2018

Category Ajax Filter Dropdown WordPress

/*Single category ajax filter dropdown example, Please Subscribe Our Blog And Comment*/
<div class="vh-filter">
  <label class="label-cate">Filter By Category</label>
  <select class="game-select-category" data-taxonomy="game-category">          
    <option class="btn fil-cat" data-rel="all">All</option>
    <?php $terms = get_terms('video_category');
        foreach($terms as $term){
        $term_name = $term->name;
        $term_slug = $term->slug;
        ?>
        <option class="btn fil-cat" data-rel="<?php echo $term_slug; ?>" value="<?php echo $term_slug; ?>"><?php echo $term_name; ?></option>
    <?php } ?>
  </select>    
</div>

<ul id="vh-lobby-posts" class="vh-row-sm">                    
<?php
$args_video = array( 'post_type' => 'PostTypeName', 'posts_per_page' => -1 );
$loop_video = new WP_Query($args_video);

if ($loop_video->have_posts()) : while ($loop_video->have_posts()) : $loop_video->the_post(); ?>              
    <?php            
        $featured_img_url = get_the_post_thumbnail_url($post->ID, 'full');
        $categorys = get_the_terms( $post->ID, 'video_category' );    
        $concats = '';
        foreach ( $categorys as $cats){
           $concats .= $cats->slug.' ';
        }   
    ?>   
    <li id="img<?php echo get_the_ID(); ?>" class="vh-item scale-anm all <?php echo $concats; ?>">
        <a href="<?php the_permalink(); ?>" class="vh-thumb-link">
            <div class="vh-overlay"><img src="<?php echo $featured_img_url; ?>" alt="<?php the_title(); ?>" title="<?php the_title(); ?>" onerror="imgError(this);" onload="vhLobbyImage.imageLoaded(<?php echo get_the_ID(); ?>)">
                <span class="play-now">Play Now</span>
            </div>
        </a>
        <div class="vh-game-title"><?php the_title(); ?></div>
    </li>
<?php endwhile; ?><?php endif; ?>
</ul>

<script>
jQuery(document).ready(function(){
    jQuery(function() {       
        var selectedClass = "";               
        jQuery('.game-select-category').change(function(){
           var selectedClass = jQuery('.game-select-category option:selected').attr('data-rel');                     
           if(selectedClass == 'all'){
               jQuery("#vh-lobby-posts li.vh-item").not("."+selectedClass).fadeOut().addClass('scale-anm');          
               setTimeout(function(){
                    jQuery("."+selectedClass).fadeIn().removeClass('scale-anm');
                    jQuery("#vh-lobby-posts").fadeTo(300, 1);
                }, 300);
           }else{          
               jQuery("#vh-lobby-posts li.vh-item").not("."+selectedClass).fadeOut().removeClass('scale-anm');          
               setTimeout(function(){
                    jQuery("."+selectedClass).fadeIn().addClass('scale-anm');
                    jQuery("#vh-lobby-posts").fadeTo(300, 1);
                }, 300);           
           }          
        });               
    });
});
</script>

-------------------------------------------------
Let me know your thoughts and questions in the comments.
Email: vyasankit2008@gmail.com

Tuesday, 17 July 2018

Device Check / Mobile Detect PHP


Download Library From : http://aksolution.co.nf/wp-content/uploads/2018/07/Mobile-Detect.zip

require_once ‘Mobile-Detect/Mobile_Detect.php’; //include library file path
$detect = new Mobile_Detect;

$deviceType = ($detect->isMobile() ? ($detect->isTablet() ? ‘tablet’ : ‘phone’) : ‘computer’); // display device 
name like : tablet,phone,computer.

$scriptVersion = $detect->getScriptVersion();
$devicedetail = $deviceType.’ ‘.$_SERVER[‘HTTP_USER_AGENT’];
//print device detail with some info.
echo “<pre>”;
print_r($devicedetail);

-------------------------------------------------
Let me know your thoughts and questions in the comments.
Email: vyasankit2008@gmail.com

Add Custom Fields To Woocommerce Products Single Page, Cart Page, Checkout Page, Order Detaile And Save To Database

<?php
//add custom fields to WooCommerce products Single Page, Cart Page, Checkout Page, Order Detaile And Save To Database Table Name "wp_woocommerce_order_itemmeta"

add_action( 'woocommerce_before_add_to_cart_button', 'add_fields_before_add_to_cart' );
function add_fields_before_add_to_cart(){ ?>
    <table>
        <tr>
            <td>
                <?php _e( "Name:", "aoim"); ?>
            </td>
            <td>
                <input type = "text" name = "customer_name" id = "customer_name" placeholder = "Name on Gift Card">
            </td>
        </tr>
        <tr>
            <td>
                <?php _e( "Gift Price:", "aoim"); ?>
            </td>
            <td>
                <input type = "text" name = "custom_price" id = "custom_price" placeholder = "Your GiftPrice on Gift Card">
            </td>
        </tr>
    </table>
    <?php
}

/**
 * Add data to cart item
 */
add_filter( 'woocommerce_add_cart_item_data', 'add_cart_item_data', 25, 2 );
function add_cart_item_data( $cart_item_meta, $product_id ) {
    if ( isset( $_POST ['customer_name'] ) && isset( $_POST ['custom_price'] ) ) {
      
        $product = wc_get_product($product_id);      
        $price = $product->get_regular_price();
      
        $custom_data  = array() ;
        $custom_data [ 'customer_name' ]    = isset( $_POST ['customer_name'] ) ?  sanitize_text_field ( $_POST ['customer_name'] ) : "" ;
        $custom_data [ 'custom_price' ] = isset( $_POST ['custom_price'] ) ? sanitize_text_field ( $_POST ['custom_price'] ): "" ;
      
        $custom_data['totalPrice'] = $price + $custom_data [ 'custom_price' ];              
      
        $cart_item_meta ['custom_data']     = $custom_data ;
    }  
    return $cart_item_meta;
}

/**
 * Display custom data on cart and checkout page.
 */
add_filter( 'woocommerce_get_item_data', 'get_item_data' , 25, 2 );
function get_item_data ( $other_data, $cart_item ) {
    if ( isset( $cart_item [ 'custom_data' ] ) ) {
        $custom_data  = $cart_item [ 'custom_data' ];          
        $other_data[] = array( 'name' => 'Name', 'display'  => $custom_data['customer_name'] );
        $other_data[] = array( 'name' => 'GiftPrice', 'display'  => $custom_data['custom_price'] );
    }
    return $other_data;
}

// Set the new calculated price replacing cart item price
add_action( 'woocommerce_before_calculate_totals', 'set_cart_item_calculated_price', 20, 1 );
function set_cart_item_calculated_price( $cart ) {
    if ( is_admin() && ! defined( 'DOING_AJAX' ) ) return;
  
    // Loop through cart items
    foreach ( $cart->get_cart() as $key=>$value ){                      
        if( ! isset( $value['custom_data']['totalPrice'] ) ){ continue; }
      
        if( $value['custom_data']['totalPrice'] > 0 ){
            $value['data']->set_price((float)$value['custom_data']['totalPrice']);
        }
    }
}

/**
 * Add order item meta.
*/
add_action( 'woocommerce_add_order_item_meta', 'add_order_item_meta' , 10, 2);
function add_order_item_meta ( $item_id, $values ) {
    if ( isset( $values [ 'custom_data' ] ) ) {
        $custom_data  = $values [ 'custom_data' ];
        wc_add_order_item_meta( $item_id, 'Name', $custom_data['customer_name'] );
        wc_add_order_item_meta( $item_id, 'GiftPrice', $custom_data['custom_price'] );
    }
}

Tuesday, 26 June 2018

Set A Featured Image By Image URL


<?php
$image_url        = $_POST['imageUrl'];
$image_name       = basename($image_url);
$upload_dir       = wp_upload_dir();
$image_data       = file_get_contents($image_url);
$genrate_unique_file_name = wp_unique_filename( $upload_dir['path'], $image_name );
$filename         = basename( $genrate_unique_file_name );
if( wp_mkdir_p( $upload_dir['path'] ) ) {
    $file = $upload_dir['path'] . '/' . $filename;
} else {
    $file = $upload_dir['basedir'] . '/' . $filename;
}
file_put_contents( $file, $image_data );
$wp_filetype = wp_check_filetype( $filename, null );

$attachment = array(
    'post_mime_type' => $wp_filetype['type'],
    'post_title'     => sanitize_file_name( $filename ),
    'post_content'   => '',
    'post_status'    => 'inherit'
);

$attach_id = wp_insert_attachment( $attachment, $file, $post_id );
require_once(ABSPATH . 'wp-admin/includes/image.php');
$attach_data = wp_generate_attachment_metadata( $attach_id, $file );
wp_update_attachment_metadata( $attach_id, $attach_data );
set_post_thumbnail( $post_id, $attach_id );
?>
-------------------------------------------------
Let me know your thoughts and questions in the comments.
Email: vyasankit2008@gmail.com

Thursday, 14 June 2018

DropDown with multiple with open select option

//Multiple Select Drop Down Code
<div class="multiselect" id="multiple">
    <?php
    global $wpdb;
    $getid= $_GET['id'];
    $sql11 = "SELECT * FROM TABLENAME WHERE id = '$getid'";
    $result11 = $wpdb->get_results($sql11);
    $count1 = 1;
    foreach($result11 as $row11){?>                             
        <label>
            <input type="checkbox" id="chknote_<?php echo $count1; ?>" name="client_check[]" class="queAns trigger" data-trigger="hidden_fields_<?php echo $count1; ?>" data-trigger-one="hidden_fields_one<?php echo $count1; ?>"  value="<?php echo $count1; ?>" />
            <?php echo $count1; ?>. <?php echo $client->lastname;?>'s <?php echo $row11->goal; ?>
        </label>
    <?php $count1++;}?>
</div>

//multiple select drop down js script
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script>
jQuery(function() {
jQuery(".multiselect").multiselect();
});
jQuery.fn.multiselect = function() {
$(this).each(function() {
var checkboxes = $(this).find("input:checkbox");
checkboxes.each(function(){
var checkbox = $(this);
if (checkbox.prop("checked"))
checkbox.addClass("multiselect-on");
checkbox.click(function() {
if (checkbox.prop("checked")){
checkbox.addClass("multiselect-on");
}else{
checkbox.removeClass("multiselect-on");
}
});
});
});
};
</script>

//open selected option script
<script>
jQuery(function() {
  jQuery('.hidden').hide();
  jQuery('.trigger').change(function() {
var hiddenId = jQuery(this).attr("data-trigger");
if (jQuery(this).is(':checked')) {
  jQuery("#" + hiddenId).show();
} else {
  jQuery("#" + hiddenId).hide();
}

var hiddenId = jQuery(this).attr("data-trigger-one");
if (jQuery(this).is(':checked')) {
  jQuery("#" + hiddenId).show();
} else {
  jQuery("#" + hiddenId).hide();
}

  });
</script>

//open selected option html/php code
<?php
global $wpdb;
$getid = $_GET['getid'];
$sql="SELECT * FROM TableName WHERE id = '$getid'";
$result=$wpdb->get_results($sql);
$count = 1;
foreach($result as $row){?>
<span id="hidden_fields_<?php echo $count; ?>"  style="display: none;">

<?php echo $count; ?>. <?php echo $client->columnName;?>'s <?php echo $row->columnName; ?>:
<p><input type="hidden" name="goal_id[]" value="<?php echo $row->columnName; ?>" /></p>         
<div class="col-md-12"> Notes:
<textarea name="note[]"  class="custom-txt-area" id="hidden_<?php echo $count; ?>"></textarea>
</div>

</span>             
<?php  $count++;} ?>

//css for dropdown
<style>
.queAns{
    margin-right:5px !important;
}
.multiselect {
    width:33em;
    height:10em;
    border:solid 1px #c0c0c0;
    overflow:auto;
    padding:5px;
}

.multiselect label {
    display:block;
}

.multiselect-on {
    color:#ffffff;
    background-color:#d29714;
}
</style>
-------------------------------------------------
Let me know your thoughts and questions in the comments.
Email: vyasankit2008@gmail.com

Thursday, 3 May 2018

Wordpress Bootstrap Navwalker Menu


<div class="navbar-header">

  <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">

    <span class="sr-only">Toggle navigation</span>

    <span class="icon-bar"></span>

    <span class="icon-bar"></span>

    <span class="icon-bar"></span>

  </button>              

</div>

<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">

  <?php             

    $main_menu = array(

        'theme_location'  => 'primary',

        'menu'            => 'Main Menu',  // menu name

        'container'       => 'div',

        'container_class' => ' ',

        'container_id'    => '',

        'menu_class'      => 'menu',

        'menu_id'         => '',

        'echo'            => true,

        'fallback_cb'     => 'wp_page_menu',

        'before'          => '',

        'after'           => '',

        'link_before'     => '',

        'link_after'      => '',

        'items_wrap'      => '<ul class="nav navbar-nav">%3$s</ul>',

        'depth'           => 0,

        'walker'          => new WP_Bootstrap_Navwalker()

    );

    wp_nav_menu( $main_menu );

    ?>                                 

</div>


//walker menu function

<?php

if ( ! class_exists( 'WP_Bootstrap_Navwalker' ) ) {

    class WP_Bootstrap_Navwalker extends Walker_Nav_Menu {

        public function start_lvl( &$output, $depth = 0, $args = array() ) {

            $indent = str_repeat( "\t", $depth );

            $output .= "\n$indent<ul class=\" dropdown-menu\" >\n";

        }

        public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {

            $indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';

            if ( 0 === strcasecmp( $item->attr_title, 'divider' ) && 1 === $depth ) {

                $output .= $indent . '<li class="divider">';

            } elseif ( 0 === strcasecmp( $item->title, 'divider' ) && 1 === $depth ) {

                $output .= $indent . '<li class="divider">';

            } elseif ( 0 === strcasecmp( $item->attr_title, 'dropdown-header' ) && 1 === $depth ) {

                $output .= $indent . '<li class="dropdown-header">' . esc_attr( $item->title );

            } elseif ( 0 === strcasecmp( $item->attr_title, 'disabled' ) ) {

                $output .= $indent . '<li class="disabled"><a href="#">' . esc_attr( $item->title ) . '</a>';

            } else {


                $classes = empty( $item->classes ) ? array() : (array) $item->classes;

                $class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args ) );

                if ( $args->has_children ) {

                    $class_names .= ' dropdown';

                }

                if ( in_array( 'current-menu-item', $classes, true ) ) {

                    $class_names .= ' active';

                }

                $class_names = 'class="' . esc_attr( $class_names ) . '"';

                $output .= $indent . '<li ' . $class_names . '>';

                $atts = array();


                if ( empty( $item->attr_title ) ) {

                    $atts['title']  = ! empty( $item->title )   ? strip_tags( $item->title ) : '';

                } else {

                    $atts['title'] = $item->attr_title;

                }

                $atts['target'] = ! empty( $item->target ) ? $item->target : '';

                $atts['rel']    = ! empty( $item->xfn )    ? $item->xfn    : '';

                if ( $args->has_children && 0 === $depth ) {

                    $atts['href']           = '#';

                    $atts['data-toggle']    = 'dropdown';

                    $atts['class']          = 'dropdown-toggle';

                    $atts['aria-haspopup']  = 'true';

                    $atts['role']  = 'button';

                } else {

                    $atts['href'] = ! empty( $item->url ) ? $item->url : '';

                }

                $atts = apply_filters( 'nav_menu_link_attributes', $atts, $item, $args );

                $attributes = '';

                foreach ( $atts as $attr => $value ) {

                    if ( ! empty( $value ) ) {


                        $value = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value );

                        $attributes .= ' ' . $attr . '="' . $value . '"';

                    }

                }

                $item_output = $args->before;

         

                if ( ! empty( $item->attr_title ) ) {

                    $pos = strpos( esc_attr( $item->attr_title ), 'glyphicon' );

                    if ( false !== $pos ) {

                        $item_output .= '<a' . $attributes . '><span class="glyphicon ' . esc_attr( $item->attr_title ) . '" aria-hidden="true"></span>&nbsp;';

                    } else {

                        $item_output .= '<a' . $attributes . '><i class="fa ' . esc_attr( $item->attr_title ) . '" aria-hidden="true"></i>&nbsp;';

                    }

                } else {

                    $item_output .= '<a' . $attributes . '>';

                }

                $item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after;

                $item_output .= ( $args->has_children && 0 === $depth ) ? ' <span class="caret"></span></a>' : '</a>';

                $item_output .= $args->after;

                $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );

            }

        }     

        public function display_element( $element, &$children_elements, $max_depth, $depth, $args, &$output ) {

            if ( ! $element ) {

                return; }

            $id_field = $this->db_fields['id'];

            if ( is_object( $args[0] ) ) {

                $args[0]->has_children = ! empty( $children_elements[ $element->$id_field ] ); }

                parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output );

        }


        public static function fallback( $args ) {

            if ( current_user_can( 'edit_theme_options' ) ) {

                $container = $args['container'];

                $container_id = $args['container_id'];

                $container_class = $args['container_class'];

                $menu_class = $args['menu_class'];

                $menu_id = $args['menu_id'];


                if ( $container ) {

                    echo '<' . esc_attr( $container );

                    if ( $container_id ) {

                        echo ' id="' . esc_attr( $container_id ) . '"';

                    }

                    if ( $container_class ) {

                        echo ' class="' . sanitize_html_class( $container_class ) . '"'; }

                    echo '>';

                }

                echo '<ul';

                if ( $menu_id ) {

                    echo ' id="' . esc_attr( $menu_id ) . '"'; }

                if ( $menu_class ) {

                    echo ' class="' . esc_attr( $menu_class ) . '"'; }

                echo '>';

                echo '<li><a href="' . esc_url( admin_url( 'nav-menus.php' ) ) . '" title="">' . esc_attr( 'Add a menu', '' ) . '</a></li>';

                echo '</ul>';

                if ( $container ) {

                    echo '</' . esc_attr( $container ) . '>'; }

            }

        }

    }

}

?>

-------------------------------------------------

Let me know your thoughts and questions in the comments.
Email: vyasankit2008@gmail.com

General Settings For Wordpress Admin


<?php
/*create theme options in admin wordpress*/
function add_general_settings_menu()
{
    add_menu_page("General Settings", "General Settings", "manage_options", "general-settings", "general_settings_page", null, 99);
}
add_action("admin_menu", "add_general_settings_menu");

function general_settings_page()
{?>
    <div class="wrap">
    <h1>General Settings</h1>
    <form method="post" action="options.php">
        <?php
            settings_fields("section");
            do_settings_sections("theme-options");     
            submit_button();
        ?>         
    </form>
    </div>
<?php }

function display_email_element(){ ?>
        <input type="text" name="emailClient" size="100" id="emailClient" value="<?php echo get_option('emailClient'); ?>" />
<?php }

function display_address_element(){ ?>
        <input type="text" name="addressClient" size="100" id="addressClient" value="<?php echo get_option('addressClient'); ?>" />
<?php }

function display_phone_element(){ ?>
        <input type="text" name="phoneClient" size="100" id="phoneClient" value="<?php echo get_option('phoneClient'); ?>" />
<?php }

function display_copyRight_element(){ ?>
        <input type="text" name="copyRight" size="100" id="copyRight" value="<?php echo get_option('copyRight'); ?>" />
<?php }

function display_facebook_element(){ ?>
        <input type="text" name="facebook_url" size="100" id="facebook_url" value="<?php echo get_option('facebook_url'); ?>" />
<?php }

function display_twitter_element(){ ?>
        <input type="text" name="twitter_url" size="100" id="twitter_url" value="<?php echo get_option('twitter_url'); ?>" />
<?php }

function display_youtube_element(){ ?>
        <input type="text" name="youtube_url" size="100" id="youtube_url" value="<?php echo get_option('youtube_url'); ?>" />
<?php }

function display_instagram_element(){ ?>
        <input type="text" name="instagram_url" size="100" id="instagram_url" value="<?php echo get_option('instagram_url'); ?>" />
<?php }

function display_theme_panel_fields()
{
    add_settings_section("section", "", null, "theme-options");
   
    add_settings_field("emailClient", "Email Address", "display_email_element", "theme-options", "section");
    add_settings_field("addressClient", "Company Address", "display_address_element", "theme-options", "section");
    add_settings_field("phoneClient", "Phone Number", "display_phone_element", "theme-options", "section");
    add_settings_field("copyRight", "Copy Right Text", "display_copyRight_element", "theme-options", "section");   
    add_settings_field("facebook_url", "Facebook Profile Url", "display_facebook_element", "theme-options", "section");
    add_settings_field("twitter_url", "Twitter Profile Url", "display_twitter_element", "theme-options", "section");   
    add_settings_field("youtube_url", "Youutbe Profile Url", "display_youtube_element", "theme-options", "section");   
    add_settings_field("instagram_url", "Instagram Profile Url", "display_instagram_element", "theme-options", "section");   
   
    register_setting("section", "emailClient");
    register_setting("section", "addressClient");
    register_setting("section", "phoneClient");
    register_setting("section", "copyRight");   
    register_setting("section", "facebook_url");
    register_setting("section", "twitter_url");
    register_setting("section", "youtube_url");
    register_setting("section", "instagram_url");   
}
add_action("admin_init", "display_theme_panel_fields");

-------------------------------------------------
Let me know your thoughts and questions in the comments.
Email: vyasankit2008@gmail.com 

Thursday, 26 April 2018

Easy OwlCarousel Slider Demo PHP/WordPress

Easy Slider Example with OwlCarousel Like :: Testimonial,Slider, ect. ::
Download the Js and Css Also from the OwlCarousel Website - with require jquery js file.

<link rel="stylesheet" href="../owlcarousel/owl.carousel.css">
<link rel="stylesheet" href="../owlcarousel/owl.theme.default.css">
<script src="../owlcarousel/owl.carousel.js"></script>
<div class="owl-carousel owl-theme">
  <div class="item">Lorem Ipsum is simply dummy text of the printing and typesetting industry.</div>
  <div class="item">Lorem Ipsum is simply dummy text of the printing and typesetting industry.</div>
  <div class="item">Lorem Ipsum is simply dummy text of the printing and typesetting industry.</div>
  <div class="item">Lorem Ipsum is simply dummy text of the printing and typesetting industry.</div>
  <div class="item">Lorem Ipsum is simply dummy text of the printing and typesetting industry.</div>
  <div class="item">Lorem Ipsum is simply dummy text of the printing and typesetting industry.</div>
  <div class="item">Lorem Ipsum is simply dummy text of the printing and typesetting industry.</div>
  <div class="item">Lorem Ipsum is simply dummy text of the printing and typesetting industry.</div>
</div>
<script>

jQuery('.owl-carousel').owlCarousel({
    loop:true,
    margin:10,
    nav:true,
    dots: false,
    //navText: ["<i class='fa fa-chevron-left'></i>","<i class='fa fa-chevron-right'></i>"],
    responsive:{
        0:{
            items:1
        },
        600:{
            items:2
        },
        1000:{
            items:2
        }
    }
})
</script>

-------------------------------------------------
Let me know your thoughts and questions in the comments.
Email: vyasankit2008@gmail.com