Articles of functions

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: 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(“”); } 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 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’ […]

get_page_templates only return templates with “home” in the filename

I have the following custom page template filenames: template-about-1.php template-about-2.php template-home-1.php template-home-2.php I have this function to get_page_templates: function get_page_templates_select() { $teh_cats = get_page_templates(); foreach ( $teh_cats as $template_name => $template_filename ) { $results[] = $template_name; } return $results; } How can I modify the function to ONLY return the templates that have “home” in […]

Overide Variable in Child Theme

I am trying to change the h1 tag in the head of my child theme from “Blog” to “Resources”. The parent theme enqueues files with require_once and get_template_directory so it’s very difficult to overwrite file through child theming. If anyone has a solution to that it would be great, but if not I thought I […]

Insert Content Before div#main from the functions.php File

I know WordPress has a filter for targeting the content in the functions.php file: add_filter( ‘the_content’) However, is there a filter to insert content BEFORE ? ‘the_content’ filter puts content AFTER div#main. I’m looking for something like: add_filter( ‘before_main’) Does a filter like that exist?