Articles of functions

WordPress can't get jquery/unslider to work

I don’t know what I’m doing wrong… I’m using the starter timber theme… I’m trying unslider to work with my theme… indicated here is somehow a proof I did right in putting scripts from the function.php… <script type=’text/javascript’ src=’http://localhost/luxjeweler/wp-content/themes/timber-starter-theme-master/includes/js/jquery.js?ver=1′></script> <script type=’text/javascript’ src=’http://localhost/luxjeweler/wp-content/themes/timber-starter-theme-master/includes/resources/bootstrap/js/bootstrap.min.js?ver=1′></script> <script type=’text/javascript’ src=’http://localhost/luxjeweler/wp-content/themes/timber-starter-theme-master/includes/js/bootstrap-wp.js?ver=1′></script> <script type=’text/javascript’ src=’http://localhost/luxjeweler/wp-content/themes/timber-starter-theme-master/includes/js/skip-link-focus-fix.js?ver=1′></script> <script type=’text/javascript’ src=’http://localhost/luxjeweler/wp-content/themes/timber-starter-theme-master/includes/unislider/js/unslider-min.js?ver=1′></script> <script type=’text/javascript’ src=’http://localhost/luxjeweler/wp-content/themes/timber-starter-theme-master/includes/js/stickyFooter.js?ver=1′></script> <script […]

How to get post category list as select in front-end?

I use widget plugin Getting the random post & URL via ajax. I want to add function, that allows users on frontend choose category, and than display random posts from this category. function get_random_post_tu() { // Simple as that, get a random post $posts = get_posts(‘orderby=rand&numberposts=1’); /** * This actually gives us an array of […]

How add body_class from wp_termmeta

I need to assign a class to the body for woocommerce categories. What I’ve done: // add the fields when the term is created add_action( ‘product_cat_add_form_fields’, ‘add_product_cat_class_field’, 10, 2 ); function add_product_cat_class_field($taxonomy) { global $feature_groups; ?><div class=”form-field term-group”> <label for=”feature-group”><?php _e(‘Custom CSS Class’, ‘my_plugin’); ?></label> <input type=”text” class=”postform” id=”custom-class” name=”custom-class” value=””> </select> </div><?php } // […]

using `require` in my functions.php breaks the site

So, I have a snippet of code I’d like to tidy away in a directory that’s close to the root my wordpress directory. Specifially it lives in /includes/inc. I’ve created a file called test.php and within it it simply says echo “XXXX”; All I currenly want to be able to do is include this file […]

remove_action not working, even after changing priority

This question already has an answer here: remove_action or remove_filter with external classes? 4 answers

Is it advisable to use $post->comment_count instead of get_comments_number( $post_id )

I was learning from the WordPress codex about global variables and after var_dump($post) I found out that $post has a property called comment_count I was wondering whether I can directly use $post->comment_count instead of get_comments_number( $post_id ) inside the loop? Or does it have any disadvantage?

Change MySQL PDO connection to a WPDB connection

I have an autofill search box with a PHP script that gets data from the DB. It uses a PDO connection, and it works perfectly even with my WordPress Database, but since I’m not sure of how PDO works, I’d like to rewrite this with WordPress functions. Does anyone know how? This is the autosuggest […]

load_plugin_textdomain error

I receive this error while debug mode is enabled: Notice: load_plugin_textdomain was called with an argument that is deprecated since version 2.7 with no alternative available. in /home/xyz/public_html/wp-includes/functions.php on line 3739 I found that is related to this plugin: https://wordpress.org/plugins/custom-smilies-se/ I really need to have this plugin and would not ignore it; Also plugin author […]

Call to undefined function error in plugin

I wrote a function inside a class that gets a user’s country from the IP address… function getcountry() { if (!class_exists(‘GeoIP’)) { include_once(“geoip.inc”); } if (empty($_SERVER[“HTTP_X_FORWARDED_FOR”])) { $ip_address = $_SERVER[“REMOTE_ADDR”]; } else { $ip_address = $_SERVER[“HTTP_X_FORWARDED_FOR”]; } $GeoIPv4_file = plugin_dir_path( __FILE__ ) . ‘data/GeoIPv4.dat’; $GeoIPv6_file = plugin_dir_path( __FILE__ ) . ‘data/GeoIPv6.dat’; if (!filter_var($ip_address, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) […]

How to use Internationalized human_time_diff() function in Chinese?

Looking at https://codex.wordpress.org/Function_Reference/human_time_diff I’m using an English version of WordPress. In my theme template, I would like to define custom text of min, hour, day, week, month, year in Chinese using human_time_diff() when looping through posts. According to the instruction in the Codex documentation: <?php printf( _x( ‘%s ago’, ‘%s = human-readable time difference’, ‘your-text-domain’ […]