728x90
1

I am using an ecommerce enabled wordpress theme! for my website along with woocommerce. Have created a childtheme, copied woocommerce.css(from the woocommerce plugin) to the child theme css and disabled the enqueuing of this woocommerce.css.

There is a woocommerce.css in my parent theme's folder structure also ( ~/wp-content/themes/shop-isle/inc/woocommerce/css/woocommerce.css).How do i override this so as to be agnostic to any theme updates?

Also - what is the difference between the woocommerce.css in the parent theme folder structure and in the woocommerce plugin folder?

1

You should create the same file in your child theme, so you will have something like this:

~/wp-content/themes/shop-isle-child/inc/woocommerce/css/woocommerce.css

This way the woocommerce.css of the parent theme will not matter.

0

So I tried various things, including using the get_stylesheet_directory() function - but nothing worked. I contacted the theme guys, and they gave me this code to override the woocommerce.css in the inc folder after replicating the folder structure in the child-theme, and it seems to work.

function ti_dequeue_script() {
  wp_dequeue_script( 'shop-isle-woocommerce-style1' );
    }
add_action( 'wp_print_scripts', 'ti_dequeue_script', 100 );

function ti_enqueue_script() {
  wp_enqueue_style( 'shop-isle-woocommerce-style2', get_stylesheet_directory_uri() . '/inc/woocommerce/css/woocommerce.css',array(), 'v3' );
   }
add_action( 'wp_enqueue_scripts', 'ti_enqueue_script', 100 );


728x90

am developing a plugin and in the admin where I provide a field that is filled in by users with a date. I am wondering if there is a native datepicker in the WP Admin I that is available.

I usually include a small jQuery datepicker script that does it, but if one is already available I would prefer that for obvious reasons like lighter code, UI consistency, etc. This seems like something that would/should be included but I've not been able to find such documentation on what jQuery stuff, if any, are available in the Admin.

    Answer has already been given, but I'd like to extend it a bit to include CSS (Wordpress doesn't provide stylesheets for jQuery UI), to help anyone passing trying to use this kind of scripts.

    Basically (and very simply), you need to have at least these three lines of code:

        wp_enqueue_script('jquery-ui-datepicker');
        wp_register_style('jquery-ui', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css');
        wp_enqueue_style('jquery-ui');

    Explanation line by line:

    1. Load jQuery UI Datepicker (library already registered by Wordpress, nothing else is necessary)
    2. Register Stylesheet with handle jquery-ui (I used the one hosted by Google, you can use whichever you prefer)
    3. Effectively include stylesheet into the ones loaded by Wordpress in this page

    And now your Datepickers will all be nice and colourful! :)

    HTML5 gift

    This is not what the OP was asking for, but it's somewhat related to the question: if you don't want to bother adding the Datepicker, you could try the HTML5 date input type, letting the browser create a very nice (and default) datepicker:

    <input type="date" name="the_date" />

    Yes, nothing else is needed (and it works in the back-end of Wordpress, too: https://jsfiddle.net/2jxdvea0/

    More info on MDN: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/date

    Note As @mark pointed out, the input does not work for Firefox (as well as for other browsers). This is noted in the MDN page, but of course it should be mentioned here as well. There are, of course, workarounds to this problem, but it would be beyond the sake of this question to write about them.

    Update 03-11-2017 As of @kosso's comment, Firefox support for this is coming in version 57

      Yes. Wordpress includes this in the core. Here are a couple articles about it:

      WP Codex: Function Reference/wp enqueue script

      Paul Underwood's Iris Color Picker Tutorial (same principles apply to datepicker)

        Add the following line of code to enqueue the jquery ui datepicker library from your plugin:

        wp_enqueue_script('jquery-ui-datepicker');

        You can download the stylesheet file from the jquery ui library site and include it in your plugin. You would then enqueue the CSS file like the following:

        wp_enqueue_style('jquery-ui-css', 'http://www.example.com/your-plugin-path/css/jquery-ui.css');

        Alternatively, You can include the jquery ui CSS from Google (you don’t need to ship the CSS files with your plugin if you go via this route):

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

        Add the following JQuery code to your javascript file so it attaches the datepicker to any fields with a class of “custom_date”:

        <script type="text/javascript">
        jQuery(document).ready(function($) {
        $('.custom_date').datepicker({
        dateFormat : 'yy-mm-dd'
        });
        });
        </script>

        Now, you can simply add class “custom_date” to the date fields in the HTML code and it will show a date picker calender when a user clicks on that field.

        <input type="text" class="custom_date" name="start_date" value=""/>
        728x90

        Almost nothing is more frustrating for a user than searching around for a login link in order to get to important content.

        The following method found at Vandweerd.com will automatically detect whether a user is logged in or not and put a login or a logout link right on your menu bar.

        *** Please note, this method only works when you are using WordPress’ custom menus. (The menu function available in the admin section: Appearance > Menus.)

        Add Code to Your Functions File

        You will need to add a bit of code to your functions file for this. But after copying and pasting this code, you’re finished.

        Go to Appearance > Editor > Theme Functions (functions.php). Place the following code in the bottom your functions file and hit “Update File.”

        add_filter('wp_nav_menu_items', 'add_login_logout_link', 10, 2);
        function add_login_logout_link($items, $args) {
                ob_start();
                wp_loginout('index.php');
                $loginoutlink = ob_get_contents();
                ob_end_clean();
                $items .= '<li>'. $loginoutlink .'</li>';
            return $items;
        }

        The Result

        Keep in mind that these links will appear wherever you put your custom menus – be they at the top of your page, in your sidebar, or anywhere else.

        Photo: login icon from BigStock

        728x90

        I just created my first WordPress Plugin. This plugin requires extra table to be created in WordPress database.

        The new table will store needed data for my plugin and this table usually created when the plugin is activated.

        In that case, I need to check if the table is already in the database or already installed due to previous installations.

        HERE’S HOW I CHECK THE DATABASE

        Sample code snippets on how to check the database.
        1
        2
        3
        4
        5
        6
        7
        8
        9
        10
        11
        12
        13
        14
        15
        16
        17
        global $wpdb;
        $table_name = $wpdb->prefix.'TABLE-NAME-HERE';
        if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name) {
             //table not in database. Create new table
             $charset_collate = $wpdb->get_charset_collate();
         
             $sql = "CREATE TABLE $table_name (
                  id mediumint(9) NOT NULL AUTO_INCREMENT,
                  field_x text NOT NULL,
                  field_y text NOT NULL,
                  UNIQUE KEY id (id)
             ) $charset_collate;";
             require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
             dbDelta( $sql );
        }
        else{
        }

        If you have questions, feel free to contact me or comment below.


        + Recent posts