Skip to content

Instantly share code, notes, and snippets.

View Tsunamijaan's full-sized avatar

Tariqul Islam Tsunamijaan

  • Coder Team IT
  • Rajshahi, Bangladesh
View GitHub Profile
@Tsunamijaan
Tsunamijaan / Not display some category products on the shop page
Created January 5, 2019 09:21
Not display some category products on the shop page
Category name(‘shirt’, ‘tshirt’, ‘pant’) which not to want display products on the shop page
add_action( 'pre_get_posts', 'custom_pre_get_posts_query' );
function custom_pre_get_posts_query( $q ) {
if ( ! $q->is_main_query() ) return;
if ( ! $q->is_post_type_archive() ) return;
@Tsunamijaan
Tsunamijaan / Load jQuery and dependent JS libraries from function.php
Created January 5, 2019 09:20
Load jQuery and dependent JS libraries from function.php
<?php
wp_enqueue_script('jquery');
if (!function_exists('load_theme_scripts')) {
function load_theme_scripts(){
wp_enqueue_script( 'custom-script', get_template_directory_uri() . '/js/custom.js', array('jquery'), '1.0.0', true );
}
add_action("wp_enqueue_scripts", "load_theme_scripts");
}
?>
@Tsunamijaan
Tsunamijaan / Get author post count inside & outside loop
Created January 5, 2019 09:20
Get author post count inside & outside loop
Inside loop:
First get user id
Then get post count in loop
$author_id= get_the_author_meta('ID');
echo count_user_posts( $author_id );
@Tsunamijaan
Tsunamijaan / Redirecting to Another URL After contact form 7 submissions
Created January 5, 2019 09:19
Redirecting to Another URL After contact form 7 submissions
On contact form 7 editor’s Additional Settings field section, just add this code.
on_sent_ok: "location = 'http://example.com/';"
#
@Tsunamijaan
Tsunamijaan / logged conditional content WordPress
Created January 5, 2019 09:18
logged conditional content WordPress
<?php if (is_user_logged_in() ): ?>
<a href="<?php echo wp_logout_url() ?>" title="Logout">Logout</a>
<?php else: ?>
<a href="http://example.com/wp-login.php" title="Logout">Member Login</a>
<?php endif ?>
@Tsunamijaan
Tsunamijaan / To Get Author information
Created January 5, 2019 09:18
To Get Author information
<?php the_author(); ?>
<?php echo get_avatar( get_the_author_email(), 'size here' ); ?>
<?php echo the_author_link(); ?>
<?php the_author_posts_link(); ?>
<?php the_author_meta( $field, $userID ); ?>
<?php the_author_meta('twitter'); ?>
<?php the_author_description(); ?>
<?php echo date("D M Y", strtotime(get_userdata(get_current_user_id( ))->user_registered)); ?>
=======To add more social fields for author:==============
@Tsunamijaan
Tsunamijaan / To use setting option
Created January 5, 2019 09:17
To use setting option
function options_page_function_name(){
add_options_page( 'manu_title', 'menu name', 'manage_options', 'option-page', 'another_page_function_name', plugins_url( 'plugin_folder_name/images/icon.png' ),8 );
}
add_action('admin_menu','options_page_function_name');
// 4. Add setting option by used function.
function register_settings_function_name() {
@Tsunamijaan
Tsunamijaan / How to register shortcode in wordpress
Created January 5, 2019 09:16
How to register shortcode in wordpress
Single shortcode======
function single_shortcode( $atts, $content = null ) {
return '<div class="singe_shortcode_wrapper">'.do_shortcode($content).'</div>';
}
add_shortcode('single_shortcode', 'single_shortcode');
=========Shortcode with attributes========
@Tsunamijaan
Tsunamijaan / WP Plugin QuickStart Pack
Created January 5, 2019 09:16
WP Plugin QuickStart Pack
//Plugin information
/*
Plugin Name: Your plugin Name
Plugin URI: http://example.com/pluginsurl
Description: Given your plugin description here.
Author: Author Name
Version: 1.0
Author URI: http://example.com/
*/
//The latest jquery need to use every plugin
@Tsunamijaan
Tsunamijaan / To Change Howdy text From WP Admin Bar
Created January 5, 2019 09:15
To Change Howdy text From WP Admin Bar
add_action( 'admin_bar_menu', 'wp_admin_bar_my_custom_account_menu', 11 );
function wp_admin_bar_my_custom_account_menu( $wp_admin_bar ) {
$user_id = get_current_user_id();
$current_user = wp_get_current_user();
$profile_url = get_edit_profile_url( $user_id );
if ( 0 != $user_id ) {
/* Add the "My Account" menu */
$avatar = get_avatar( $user_id, 28 );