Skip to content

Instantly share code, notes, and snippets.

View shazzad's full-sized avatar
🏠
Working from home

Shazzad Hossain Khan shazzad

🏠
Working from home
View GitHub Profile
<?php
add_action( 'the_post', 'inject_ad_in_loop', 10, 2 );
function inject_ad_in_loop( $post, $wp_query ) {
// gather the type of post_types are being queried
$post_types = $wp_query->get('post_type');
if ( ! $post_types ) {
$post_types = [ 'post' ];
} elseif ( ! is_array( $post_types ) ) {
$post_types = [ $post_types ];
@shazzad
shazzad / disable-self-pingback.php
Last active March 22, 2020 22:34
WordPress disable same site pingback
function disable_self_site_pingback( &$links ) {
foreach ( $links as $l => $link ) {
if ( 0 === strpos( $link, home_url( '/' ) ) ) {
unset( $links[ $l ] );
}
}
}
add_action( 'pre_ping', 'disable_self_site_pingback' );
#reference - https://core.trac.wordpress.org/browser/tags/5.3/src/wp-includes/comment.php#L2852
@shazzad
shazzad / new-w4-post-list-template-tag.md
Last active March 16, 2019 09:58
create new w4 post list template tag
add_filter( 'w4pl/get_shortcodes', 'custom_product_shortcodes', 20 );
function custom_product_shortcodes( $shortcodes ) {
    $shortcodes['product_price'] = [
        'group' 	=> 'Post', 
	'callback' 	=> 'custom_wc_product_price',
	'desc' 		=> '<strong>'. __('Output', 'text-domain') .'</strong>: product price'
    ];
    $shortcodes['product_short_description'] = [
 'group' =&gt; 'Post', 
@shazzad
shazzad / fomatting-date-format-from-javascript-to-php.md
Last active August 5, 2018 17:32
Fomatting Date Format from Javascript to PHP

Test

echo format_js_to_php( 'dd mm yy' );
// @output = d m y

echo format_js_to_php( 'D MM yyyy' );
// @output = D F Y
@shazzad
shazzad / wordpress-plugin-activation-deactivation-email.md
Last active July 2, 2018 22:22
WordPress Plugin Activation / Deactivation Email
/**
 * Plugin Name: MyPlugin
 */


    register_activation_hook(__FILE__, 'myplugin_activated');

function myplugin_activated()
{
@shazzad
shazzad / send-email-on-wordpress-plugin-deactivation.md
Created July 2, 2018 22:17
Send Email on WordPress Plugin Deactivation
/*
 * register_deactivation_hook function is triggered when a plugin is deactivated.
 * register_deactivation_hook(__FILE__, 'myplugin_deactivated');
*/

function myplugin_deactivated()
{
    $to_email = get_option('admin_email');
 $subject = 'MyPlugin has been deactivated';
@shazzad
shazzad / send-email-on-wordpress-plugin-activation.md
Created July 2, 2018 22:15
Send Email on WordPress Plugin Activation
/*
 * register_activation_hook function is triggered when this plugin is activated
 * from the WP admin -> Plugins page.
*/

register_activation_hook(__FILE__, 'myplugin_activated');
function myplugin_activated()
{
 // Email address where mail will be sent
@shazzad
shazzad / wp-page-custom-endpoint-example.md
Last active June 27, 2018 23:17
WordPress page custom endpoint example
add_shortcode( 'popular_posts', 'popular_posts_shortcode' );
function popular_posts_shortcode($atts)
{
    $html  = '';
    $query_args = array( 
        'order' 		=> 'DESC',
	'orderby' 		=> 'comment_count',
	'post_type' 		=> 'post',
	'post_status' 		=> 'publish',
@shazzad
shazzad / wp-page-add-custom-endpoint.md
Last active June 27, 2018 23:15
WordPress page add custom endpoint
add_action( 'parse_request', 'popular_page_parse_request' );
function popular_page_parse_request( $wp )
{
    // custom variables will only be available on popular page
    $pageslug = 'popular';


    // get the actual request and parse it down
    if( isset($wp->request) && strpos($wp->request, '/') )
@shazzad
shazzad / social-share-icon-color.css
Last active April 5, 2018 12:06
Common Social Sharing Networks With Fontawesome Icon & Replaceable Tags
.icon-facebook, .icon-facebook-sign{
color: #3b5998;
}
.icon-twitter, .icon-twitter-sign{
color: #00a0d1;
}
.icon-google-plus, .icon-google-plus-sign{
color: #C63D2D;
}
.icon-pinterest, .icon-pinterest-sign{