Skip to content

Instantly share code, notes, and snippets.

View obiPlabon's full-sized avatar
🎯
1 goal

Md Obidullah obiPlabon

🎯
1 goal
View GitHub Profile
@obiPlabon
obiPlabon / wp-single-page-nav-filter.php
Last active August 29, 2015 14:17
Created only for my personal reference.
function op_filter_single_page_nav( $atts, $item ) {
if ( ! is_page( get_option( 'page_on_front' ) ) && 'section' == get_post_type( $item->object_id ) ) {
$atts['href'] = home_url() . '#section-' . $item->object_id;
} elseif ( is_page( get_option( 'page_on_front' ) ) && 'section' == get_post_type( $item->object_id ) ) {
$atts['href'] = '#section-' . $item->object_id;
}
return $atts;
}
add_filter( 'nav_menu_link_attributes', 'op_filter_single_page_nav', 10, 2 );
@obiPlabon
obiPlabon / wp-hook-list.php
Created March 24, 2015 09:19
List all WordPress hooks.
function list_hooked_functions($tag=false){
global $wp_filter;
if ($tag) {
$hook[$tag]=$wp_filter[$tag];
if (!is_array($hook[$tag])) {
trigger_error("Nothing found for '$tag' hook", E_USER_WARNING);
return;
}
}
else {
@obiPlabon
obiPlabon / plugin-check.js
Last active August 29, 2015 14:21
Initialize plugin based on its existence
// Initialize plugin based on its existence
//
// if ( $.isFunction( $.fn.pluginMethodName ) )
// $(selector).pluginMethodName();
//
// Note: you can ommit the $.isFunction
// simply write
// if ( $.fn.pluginMethodName )
// Example
<?php
function dequeue_scripts_on_condition() {
// you can use various conditional tags
// ex. is_page(), is_page_template()
if ( ! is_page( /* page id */ ) )
wp_dequeue_script( $handle );
if ( ! is_page_template( /* page template name */ ) )
wp_dequeue_script( $handle );
//
// @pram a Array
//
var a = [1,2,3,[4,5,6,[7,8,9]]];
function recursiveMulti(a){
return a.map(function(i){
if(Object.prototype.toString.call(i) === "[object Array]")
return recursiveMulti(i);
function list_wpcf7_form_shortcodes() {
global $post;
if ( ! post_type_exists( 'wpcf7_contact_form' ) )
_e( "You haven't install/activate Contact Form 7 plugin yet.", "text_domain" );
$wpcf7_posts = get_posts( array(
'post_type' => 'wpcf7_contact_form',
'posts_per_page' => -1,
/**
* Get posts pending count as per Post Type.
* @param string $post_type
* @return integer Pending count.
*/
function project_get_pending_items( $post_type ) {
global $wpdb;
$pending_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = %s AND post_status = 'pending'", $post_type ) );
return (int) $pending_count;
}
@obiPlabon
obiPlabon / customize-nav-item.php
Created July 20, 2015 09:02
Customize navigation menu title
<?php
function customize_nav_item( $title, $id ) {
if ( 'nav_menu_item' === get_post_type( $id ) ) {
$title = sprintf( '<span data-hover="%1$s">%2$s</span>',
esc_attr( $title ),
$title
);
}
return $title;
@obiPlabon
obiPlabon / .csscomb.json
Created July 30, 2015 10:51
css comb config file based on WordPress css standard
{
"remove-empty-rulesets": true,
"always-semicolon": true,
"color-case": "lower",
"block-indent": " ",
"color-shorthand": true,
"element-case": "lower",
"eof-newline": true,
"leading-zero": false,
"quotes": "double",
@obiPlabon
obiPlabon / obi-nav-metabox.php
Last active October 16, 2015 17:37
Add metabox to WordPress menu editor
<?php
//add_action( 'admin_init', 'obi_add_meta_box' );
// load-nav-menus.php is the perfect hook for this metabox
// as we are only adding on nav menu page :)
add_action( 'load-nav-menus.php', 'obi_add_meta_box' );
function obi_add_meta_box() {
add_meta_box(
'obi-nav-metabox',