Category: Wordpress Snippets

Sort WordPress Posts With Multiple Criteria
[ad_1] By OutsourcedContent — on December 10, 2017 This was a case on a project where a custom listing post type had post meta that specified if it was as platinum sponsor, or a gold sponsor or a verified profile. The job was to list the platinum sponsors at the top on the archive page,…

Easy Tabbed Navigation With jQuery
[ad_1] By OutsourcedContent — on December 10, 2017 Here is the HTML Markup <h4 class=”single-company-tab-wrapper hide-if-no-js”> <a class=”single-company-tabs” href=”#info”>Info</a> <a class=”single-company-tabs” href=”#contact”>Contact</a> </h4> <div id=”info” class=”tab-content”> <p>Content of info tab</p> </div> <div id=”contact” class=”tab-content”> <p>Content of contact tab</p> </div> And here is the jQuery jQuery( document ).ready( function($){ $(‘.tab-content’).hide(); // Hide all tabs…

Add Custom Image Sizes Into WordPress Media Library
[ad_1] In a previous article we have posted about how you can define new custom image sizes to use on your WordPress theme and how to remove default image sizes. You can define and add custom image sizes with the help of add_image_size() function in WordPress. In this article we will show you how you…

Debugging WordPress With error_log()
[ad_1] By OutsourcedContent — on January 6, 2018 If Debug logging is enabled, simply use the error_log() function and it will be written to /wp-content/debug.log . Refer this article to see how it can be done: Enable Debug Logging In WordPress You can also write the error_log to a file. WP_DEBUG need not be set…

Full Width Responsive WordPress YouTube Embeds Automatically
[ad_1] By OutsourcedContent — on January 12, 2018 Add this to the functions.php /** * Add Response code to video embeds in WordPress * * @refer http://alxmedia.se/code/2013/10/make-wordpress-default-video-embeds-responsive/ */ function abl1035_alx_embed_html( $html ) { return ‘<div class=”video-container”>’ . $html . ‘</div>’; } add_filter( ’embed_oembed_html’, ‘abl1035_alx_embed_html’, 10, 3 ); add_filter( ‘video_embed_html’, ‘abl1035_alx_embed_html’ ); // Jetpack Add this…

Add Left And Right Swipe On Mobile For Bootstrap 4 Carousel
[ad_1] By OutsourcedContent — on January 13, 2018 We are talking about carousel included in Bootstrap 4, you can see how to add one here. Add this to your JS file or load it on the footer // Thanks to Maaaaark – https://github.com/maaaaark/bcSwipe/blob/master/jquery.bcSwipe.min.js !function(t){t.fn.bcSwipe=function(e){var n={threshold:50};return e&&t.extend(n,e),this.each(function(){function e(t){1==t.touches.length&&(u=t.touches[0].pageX,c=!0,this.addEventListener(“touchmove”,o,!1))}function o(e){if(c){var o=e.touches[0].pageX,i=u-o;Math.abs(i)>=n.threshold&&(h(),t(this).carousel(i>0?”next”:”prev”))}}function h(){this.removeEventListener(“touchmove”,o),u=null,c=!1}var u,c=!1;”ontouchstart”in document.documentElement&&this.addEventListener(“touchstart”,e,!1)}),this}}(jQuery); // Swipe…

Redirect User To Post If Search Results Return One Post
[ad_1] Recently on a project, my client asked me to develop a system to redirect user to post if search results returns only one post. Although it’s fairly simple system to develop but I started searching on Google if someone has already tried to develop similar function. Fortunately WordPress developer Paul Underwood has shared a…

Unhooking Actions Hooked Inside PHP Classes With remove_action
[ad_1] By OutsourcedContent — on April 13, 2018 Here is an example. The following snippet removes the action hooked from the SumoMe plugin – https://wordpress.org/plugins/sumome/ /** * Dequeue SumoMe inline script * * @author Arun Basil Lal */ function rocket_helper_dequeue_sumo_me_js() { global $wp_plugin_sumome; remove_action(‘admin_footer’, array( $wp_plugin_sumome, ‘append_admin_script_code’ ) ); } add_action( ‘admin_head’, ‘rocket_helper_dequeue_sumo_me_js’ );…

Read Plugin Version Of Any WordPress Plugin
[ad_1] By OutsourcedContent — on April 19, 2018 Using the get_file_data() function. More efficient than using get_plugin_data() function. $plugin_data = get_file_data( WP_PLUGIN_DIR . ‘/plugin-folder-name-in-wp-content-plugins-folder/plugin-main-file.php’, array( ‘Version’ => ‘Version’ ) ); $plugin_data[‘Version’] will have the version. To read version from within the same plugin: $plugin_data = get_file_data( __FILE__, array( ‘Version’ => ‘Version’ ) ); Refer: https://wordpress.stackexchange.com/a/285644/90061…

Add Custom Post Type To Tag And Category Archive Pages
[ad_1] By OutsourcedContent — on May 20, 2018 Here is how to modify the query for default taxonomy archive pages (tag archive page or category archive page) to display custom post types. /** * Add custom post types to the default tag query * * This will make sure that the custom post types…