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 / WordPress image crop
Created January 5, 2019 09:58
WordPress image crop
View WordPress image crop
add_theme_support( 'post-thumbnails');
===========================
WordPress crop an image = 5 size. Sizes are given below
thumbnail: Thumbnail (default 150px x 150px max)
medium: Medium resolution (default 300px x 300px max)
large: Large resolution (default 640px x 640px max)
@Tsunamijaan
Tsunamijaan / Custom post loop with custom fields
Created January 5, 2019 09:56
Custom post loop with custom fields
View Custom post loop with custom fields
<?php
global $post;
$args = array( 'posts_per_page' => -1, 'post_type'=> 'posttype', 'orderby' => 'menu_order', 'order' => 'ASC' );
$myposts = get_posts( $args );
foreach( $myposts as $post ) : setup_postdata($post); ?>
<?php
$job_link= get_post_meta($post->ID, 'job_instructions', true);
?>
@Tsunamijaan
Tsunamijaan / Enable masonry in WordPress
Created January 5, 2019 09:56
Enable masonry in WordPress
View Enable masonry in WordPress
add_action( 'wp_enqueue_scripts', 'jk_masonry' );
function jk_masonry() {
wp_enqueue_script( 'jquery-masonry', array( 'jquery' ) );
}
How to use? =======
$('#container').masonry({ singleMode: true });
OR ===========
$('#container').masonry({ columnWidth: 200 });
@Tsunamijaan
Tsunamijaan / Shortcode inside custom post wordpress
Created January 5, 2019 09:55
Shortcode inside custom post wordpress
View Shortcode inside custom post wordpress
function post_list_shortcode($atts){
extract( shortcode_atts( array(
'count' => '',
), $atts) );
$q = new WP_Query(
array('posts_per_page' => $count, 'post_type' => 'posttype', 'orderby' => 'menu_order','order' => 'ASC')
);
$list = '<div class="custom_post_list">';
@Tsunamijaan
Tsunamijaan / Register widget in wordpress
Created January 5, 2019 09:54
Register widget in wordpress
View Register widget in wordpress
function my_custom_theme_widgets() {
register_sidebar( array(
'name' => 'My Widget',
'id' => 'widget_id',
'before_widget' => '<div class="widget_div">',
'after_widget' => '</div>',
'before_title' => '<h2>',
'after_title' => '</h2>',
) );
}
@Tsunamijaan
Tsunamijaan / Register option tree metabox
Created January 5, 2019 09:53
Register option tree metabox
View Register option tree metabox
function my_theme_custom_meta_boxes() {
$post_meta_box = array(
'id' => 'post_meta_box',
'title' => 'Metabox',
'pages' => array( 'post' ),
'context' => 'normal',
'priority' => 'high',
'fields' => array(
array(
@Tsunamijaan
Tsunamijaan / Register custom post & custom taxonomy in wordpress
Created January 5, 2019 09:53
Register custom post & custom taxonomy in wordpress
View Register custom post & custom taxonomy in wordpress
Register custom post type
add_action( 'init', 'my_theme_custom_post' );
function my_theme_custom_post() {
register_post_type( 'cpt',
array(
'labels' => array(
'name' => __( 'CPTs' ),
'singular_name' => __( 'CPT' )
),
@Tsunamijaan
Tsunamijaan / Dynamic wordpress menu
Created January 5, 2019 09:52
Dynamic wordpress menu
View Dynamic wordpress menu
add_action('init', 'my_theme_register_menu');
function my_theme_register_menu() {
register_nav_menu( 'main-menu', 'Main Menu');
}
// Default menu
function my_theme_default_menu() {
echo '<ul id="nav">';
if ('page' != get_option('show_on_front')) {
@Tsunamijaan
Tsunamijaan / How to activate option tree in wordpress theme
Created January 5, 2019 09:50
How to activate option tree in wordpress theme
View How to activate option tree in wordpress theme
add_filter( 'ot_show_pages', '__return_false' );
add_filter( 'ot_show_new_layout', '__return_false' );
add_filter( 'ot_theme_mode', '__return_true' );
include_once( 'option-tree/ot-loader.php' );
@Tsunamijaan
Tsunamijaan / How to add favicon in wordpress website?
Created January 5, 2019 09:50
How to add favicon in wordpress website?
View How to add favicon in wordpress website?
Make sure you used this before </head>
If you have favicon as .ico format, you can use this code.
<link type="image/x-icon" rel="shortcut icon" href="<?php echo get_template_directory_uri(); ?>/img/favicon.ico">
If you have favicon as png image format, you can use this code. Make sure your favicon size is 16x16px
<link rel="shortcut icon" type="image/png" href="<?php echo get_template_directory_uri(); ?>/img/favicon.png"/>