3 WordPress Tricks Every PHP Programming Expert Should Know

WordPress uses PHP as the scripting language. It means that if you an expert in PHP, you can do a lot of changes in a WordPress blog and make it a unique piece of work. In this article, we will cover all the different WP hacks that you can easily do as a PHP programmer.

PHP and WordPress: What’s the connection?

WordPress experts are often PHP programmers. PHP is a server-side programming language. It is an open source and has been used for scripting the WordPress (which is again an open source platform for blogs and sites). It means that when a user makes a request on a web page with the PHP code embedded in it, the web server processes the module and generates the HTML output which is displayed on the user’s screen.

WordPress uses PHP files that end with .php extension as well as PHP codes embedded inside HTML documents between the opening and closing tags of PHP which are ‘‘ respectively.

While a general blog writer does not need to learn PHP to blog in WordPress, a basic idea of PHP coding, HTML, and CSS opens up a whole new opportunity for you to develop new WordPress themes and plugins, and modify the default behavior of the online blogging platform.

The default plugin called ‘functions.php’ comes with all free and premium WordPress themes. It can help you define actions and filters on a WordPress site which might include the format of your post, thumbnails, and navigation menus.

Functions.php Tricks you should try

Open your functions.php file and add the following codes to

1. Remove the WordPress Version Number

Displaying your WordPress version can pose a security risk to your website. This crucial information makes it easier for hackers to exploit the vulnerabilities a particular version of WP might have.

Here is how you to obscure the WP version number easily:

remove_action('wp_head', 'wp_generator');

to remove the version number from header.

add_filter('the_generator', '__return_empty_string');

to remove the version number from RSS feeds.

function shapeSpace_remove_version_scripts_styles($src) {
if (strpos($src, 'ver=')) {
$src = remove_query_arg('ver', $src);
}
return $src;
}
add_filter('style_loader_src', 'shapeSpace_remove_version_scripts_styles', 9999);
add_filter('script_loader_src', 'shapeSpace_remove_version_scripts_styles', 9999);

to remove the version number from scripts and styles.

2. Optimize Your RSS Feeds

function wpbeginner_postrss($content) {
if(is_feed()){
$content = 'This post was written by Syed Balkhi '.$content.'Check out WPBeginner';
}
return $content;
}
add_filter('the_excerpt_rss', 'wpbeginner_postrss');
add_filter('the_content', 'wpbeginner_postrss');

to show advertisements below each post.

function rss_post_thumbnail($content) {
global $post;
if(has_post_thumbnail($post->ID)) {
$content = '<p>' . get_the_post_thumbnail($post->ID) .
'</p>' . get_the_content();
}
return $content;
}
add_filter('the_excerpt_rss', 'rss_post_thumbnail');
add_filter('the_content_feed', 'rss_post_thumbnail');

to display features images or thumbnails in your RSS feed.

function publish_later_on_feed($where) {

global $wpdb;

if ( is_feed() ) {
// timestamp in WP-format
$now = gmdate('Y-m-d H:i:s');

// value for wait; + device
$wait = '10'; // integer

// http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_timestampdiff
$device = 'MINUTE'; //MINUTE, HOUR, DAY, WEEK, MONTH, YEAR

// add SQL-sytax to default $where
$where .= " AND TIMESTAMPDIFF($device, $wpdb->posts.post_date_gmt, '$now') > $wait ";
}
return $where;
}

add_filter ('posts_where', 'publish_later_on_feed');

to delay the distribution of your article to the RSS feed subscribers by 10 minutes. You can change ‘$wait’ to any number of minutes you like. This will allow you some time to make any last-minute corrections (such as spelling errors or grammatical mistakes) in your article before the distribution gets triggered.

3. Enable Infinite Scrolling in WordPress

A well-coded theme like the default WP theme allows you to enable infinite scrolling with the help of Jetpack plugin feature. You just have to install the plugin (Jetpack) and enable the infinite scroll feature along with adding the following code to the functions.php file:

add_theme_support( 'infinite-scroll', array(
'container' => 'content',
'footer' => 'page',
) );

Final Thoughts

Once you learn how to code WordPress, setting up custom queries and using looks becomes easy and quite straightforward. While WordPress allows you to modify core files, many experts strictly advise against it. Instead, you can use actions and filters to do what you desire or use child themes to implement the modifications you desire.

About The Author:

Rruchi Shrimalli is a Content Marketing Manager for transtutors.com, askIITians.com, GoAssignmentHelp.com.au and several other websites. She is a writer and a journalist at heart and has been writing articles on various aspects of the Education domain since 2010. Her articles have been published at Shiksha.com, India.com, and Employment News among others.