WordPress Information

ওয়ার্ডপ্রেস টার্মিনোলজি

1.slug (mean user friendly url)
2.Template Hierarchy ( ওয়ার্ডপ্রেসে পাট্টিকুলারলি যদি কিছু ফাইল থাকে ওয়ার্ডপ্রেস আগে সেই ফাইলটা দিয়ে কন্টেন্ট দেখায়। যদি ওটা না থাকে তাহলে আরেকটা ফাইল দিয়ে চেক করে যে এ ফাইলটা আছে কিনা তখন সেটা দিয়ে কন্টেন্ট দেখায়। যদি সেটাও না থাকে তাহলে আরেকটা ফাইল দিয়ে কন্টেন্ট দেখায় এভাবে সবশেষে কেউ যদি না থাকে তাহলে index.php দিয়ে কন্টেন্ট দেখায়। এই যে ওর্ডারটা, কন্টেন্ট দেখানোর জন্য কোন টেমপেল্ট ফাইলটা লোড হবে কোন php ফাইলটা লোড হবে। এই ওর্ডারটাকেই বলা হয় Template Hierarchy )

3.Taxonomy And Terms (Categories, Tags)
4.Transient (Temporary Storage)

What is hook?

হুক আসলে জাস্ট একটা ইভেন্ট ব্রডকাস্টিং সিস্টেম। দুই রকমের হুক আছে, অ্যাকশন হুক এবং ফিল্টার হুক

প্লাগেবল ফাংশন কি?

একটা ফাংশনকে এমন ভাবে ডিফাইন করা হয়, যাতে করে ইউজার সেই ফাংশনটি রিরাইট করতে পারে। অথাৎ একটা কন্ডিশনের ভিক্তিতে চেক করা হয় ফাংশনটি লিখা হয়েছে কিনা? যদি না হয় তাহলে ফলবেক হিসেবে কারেন্ট ফাংশনটিকে রির্টান করে। আর যদি থাকে তার মানে সেই existing ফাংশনটিকে নতুন করে লিখা হয়েছে। তখন সে নতুনটাকে রির্টান করে।

Advertisements

WordPress topics

|| if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly
   }
 
   It prevent public user to directly access your .php files through URL.
   Usage:
   It can be placed at the top of any of your PHP files (theme & plugin)
   It can be placed at the top of your wp-config.php 

WordPress Snippets


<?php
/* Tag list */
the_tags(' ', ' ', ' ');
echo get_the_tag_list("<ul class=\"list-unstyled text-center\"><li>", "</li><li>", "</li></ul>");

/* Get All tags */
$tags = get_tags();
$html = '<div class="post_tags">';
foreach ( $tags as $tag ) {
	$tag_link = get_tag_link( $tag->term_id );
			
	$html .= "<a href='{$tag_link}' title='{$tag->name} Tag' class='{$tag->slug}'>";
	$html .= "{$tag->name}</a>";
}
$html .= '</div>';
echo $html;


/* Post thumbnail */
if(has_post_thumbnail()){
	the_post_thumbnail('large', array('class' => 'img-fluid'));   
}

/* Comments */
if(comments_open()): ?>
	<div class="col-md-10 offset-md-1">
		<?php comments_template();?>
	</div>
<?php endif;


/* Post pagination */
the_posts_pagination(array(
	"screen_reader_text" => ' '
	)
);

/* template file included */
get_template_part('');


/* php file or lib included */
get_theme_file_path('');


/* post navigation */
next_post_link();
echo "<br>";
previous_post_link();


/* password protected post */
function alpha_protected_post($excerpt){
	if (! post_password_required()) {
		return $excerpt;
	}else{
		echo get_the_password_form();
	}
}

add_filter('the_excerpt', 'alpha_protected_post');


/* css added in header */
function launcher_style(){
	if (is_page()) {
		$thumb_img = get_the_post_thumbnail_url( null, 'large' );
		?>
		<style>
			.home-side{
				background-image: url(<?php echo $thumb_img;?>);
			}
		</style>
		<?php
	}
}

add_action( 'wp_head', 'launcher_style', 11);


/* custom meta field data retrieve */
$placeholder = get_post_meta( get_the_ID(), 'placeholder', true );


/* post format */
$alpha_format = get_post_format();


/* author info */
get_the_author_meta();


/* author image */
echo get_avatar( get_the_author_meta( 'id') );


/* body class remove or add */
function alpha_body_class($classes){
	unset($classes[array_search('wp-custom-logo', $classes)]);
	$classes[] = "newclass_add";
	return $classes;
}

add_filter( 'body_class','alpha_body_class');


/* post class remove or add */
function alpha_post_class($classes){
	unset($classes[array_search('tag-blog', $classes)]);	
	return $classes;
}

add_filter( 'post_class','alpha_post_class');


/* image srcset remove */
function alpha_image_srcset(){
	return null;
}
add_filter( 'wp_calculate_image_srcset', 'alpha_image_srcset' );


/* If you want to override a function into the child theme, just put in a check */
if(!function_exists('alpha_date')) {
	function alpha_date(){
		echo date("d/m/y");
	}
}

?>

Woocommerce Snippets

/****************************/

Woocommerce:
===============

|| Related products
   plugins > woocommerce > templates > single-product > related.php


|| how to move best seller product on the top
   go to storefront-template-hooks.php
   add_action( 'homepage', 'storefront_best_selling_products', 70 ); 
                      to
   add_action( 'homepage', 'storefront_best_selling_products', 10 );


|| img src directory
   <img src="<?php echo get_template_directory_uri(); ?>/assets/images/bd.jpg" width="" height="" alt="" />

|| custom css add
   <link rel="stylesheet" type="text/css" href="<?php echo get_stylesheet_directory_uri(). '/assets/css/custom.css' ?>">

|| Add Custom Fonts, top of the style.css file
   @font-face {
	font-family: calib;
	src: url('assets/fonts/calibrib.ttf');
}

|| search form anywhere
   <form role="search" method="get" class="woocommerce-product-search" action="<?php echo esc_url( home_url( '/'  ) ); ?>">
	<label class="screen-reader-text" for="s"><?php _e( 'Search for:', 'woocommerce' ); ?></label>
	<input type="search" class="search-field" placeholder="<?php echo esc_attr_x( 'Search Products&hellip;', 'placeholder', 'woocommerce' ); ?>" value="<?php echo get_search_query(); ?>" name="s" title="<?php echo esc_attr_x( 'Search for:', 'label', 'woocommerce' ); ?>" />
	<input type="submit" value="<?php echo esc_attr_x( 'Search', 'submit button', 'woocommerce' ); ?>" />
	<input type="hidden" name="post_type" value="product" />
   </form>


|| Number of related products
   add_filter( 'woocommerce_output_related_products_args', 'jk_related_products_args' );
   function jk_related_products_args( $args ) {
	$args['posts_per_page'] = 4; // 4 related products
	$args['columns'] = 3; // arranged in 3 columns
	return $args;
}


|| How to Remove Product Review,  go to functions.php
   	add_filter( 'woocommerce_product_tabs', 'helloacm_remove_product_review', 99);
	function helloacm_remove_product_review($tabs) {
		unset($tabs['reviews']);
		return $tabs;
	}

|| remove sidebar from product view page,  go to functions.php
   /* Storefront Theme – Remove WooCommerce Sidebar on the Single Product Page */
	add_action( 'get_header', 'bbloomer_remove_storefront_sidebar' );
	function bbloomer_remove_storefront_sidebar() {
	    if ( is_product() ) {
	        remove_action( 'storefront_sidebar', 'storefront_get_sidebar', 10 );
	    }
	}

|| add to cart text change, go to functions.php
   
   /* custom function add for add to cart text change */
	add_filter( 'woocommerce_product_add_to_cart_text', 'woo_archive_custom_cart_button_text' );    // 2.1 + 
	function woo_archive_custom_cart_button_text() {
	    return __( 'BY NOW', 'woocommerce' );
	}

|| how to change product column
   your theme > inc > woocommerce > storefront-woocommerce-template-functions.php
   search storefront_loop_columns

|| How do I add WooCommerce product categories to a custom menu?
    Go to Appearance > Menus
    In the upper right corner, click on Screen Options and ensure the "Products" and "Product Categories" boxes are checked

|| Display My Account link in a template file
   <?php if ( is_user_logged_in() ) { ?>
      <a href="<?php echo get_permalink( get_option('woocommerce_myaccount_page_id') ); ?>" title="<?php _e('My Account','woothemes'); ?>"><?php _e('My Account','woothemes'); ?></a>
   <?php } 
   else { ?>
      <a href="<?php echo get_permalink( get_option('woocommerce_myaccount_page_id') ); ?>" title="<?php _e('Login / Register','woothemes'); ?>"><?php _e('Login / Register','woothemes'); ?</a>
   <?php } ?>

|| How to enable registration on "My Account" page
   Go to WooCommerce > Settings > Account and  Enable customer registration on the "My account" page.

|| How To Change Product Images Size?
   1st woocommerce > setting > product > Display > Product Images
   2nd Regenerate Thumbnails plugins install and active
   tutorial link: https://www.youtube.com/watch?v=YVLb3eG0JdI
   

|| product detail page sku and category
   wp-content\plugins\woocommerce\templates\single-product\meta.php

|| Product listing page product name
   content-product.php
   <a href="<?php the_permalink(); ?>">---- </a>

|| product view page review tab remove

<?php
	add_filter( 'woocommerce_product_tabs', 'sb_woo_remove_reviews_tab', 98);
	function sb_woo_remove_reviews_tab($tabs) {

	 unset($tabs['reviews']);

	 return $tabs;
	}
?>

|| product view short description:
   woocommerce/single-product/short-description.php

|| breadcrumbs slash '/' replace as '>'
   function.php

<?php
	add_filter( 'woocommerce_breadcrumb_defaults', 'my_change_breadcrumb_delimiter' );
	function my_change_breadcrumb_delimiter( $defaults ) {
	 // Change the breadcrumb delimiter from '/' to '>'
	 $defaults['delimiter'] = ' > ';
	 return $defaults;
	}
?>

|| Default breadcrumbs remove from product page:
   function.php
   <?php remove_action( 'woocommerce_before_main_content','woocommerce_breadcrumb', 20, 0);?>

|| prodcut view page related product remove
   function.php
   <?php remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20 );?>

|| Add to cart remove:
        <?php
		/* product listing page add to cart remove */
		function remove_loop_button(){
			remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
		}
		add_action('init','remove_loop_button');
			or
		remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart' );
		
		/* product detail page add to cart remove */
		remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
		
	?>

|| Price Remove
       <?php
		/* product listing page price remove */
		remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );
		/* product detail page price remove */
		remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
		
	?>

|| edit products page:

You need to add a folder to your theme named "woocommerce" and copy the contents from the woocommerce plugin folder under "templates", 
copy archive-product.php and paste your theme woocommerce folder. The loop folder contains the files you want to use. 
so, in your theme, you'd have something like
themefolder/woocommerce/archive-product.php
themefolder/woocommerce/loop/...
<?php
	do_action( 'woocommerce_sidebar' )
?>


|| Dynamic Product Category in sidebar:
   Appearance > Widget:
   drag and drop (WooCommerce Product Categories) in (primary sidebar) or (secondary widget area)

|| Dynamic product category anywhere:
   function.php

<?php
	/* product category */
	function wooCommerceCategories() {

		$taxonomy     = 'product_cat';
		$orderby      = 'name';  
		$show_count   = 0;      // 1 for yes, 0 for no
		$pad_counts   = 0;      // 1 for yes, 0 for no
		$hierarchical = 1;      // 1 for yes, 0 for no  
		$title        = '';  
		$empty        = 0;

		$args = array(
			'taxonomy'     => $taxonomy,
			'orderby'      => $orderby,
			'show_count'   => $show_count,
			'pad_counts'   => $pad_counts,
			'hierarchical' => $hierarchical,
			'title_li'     => $title,
			'hide_empty'   => $empty
		);
		$all_categories = get_categories( $args );
		 foreach ($all_categories as $cat) {
			if($cat->category_parent == 0) {
				$category_id = $cat->term_id;       
				echo '<br /><a href="'. get_term_link($cat->slug, 'product_cat') .'">'. $cat->name .'</a>'; 
				$args2 = array(
						'taxonomy'     => $taxonomy,
						'child_of'     => 0,
						'parent'       => $category_id,
						'orderby'      => $orderby,
						'show_count'   => $show_count,
						'pad_counts'   => $pad_counts,
						'hierarchical' => $hierarchical,
						'title_li'     => $title,
						'hide_empty'   => $empty
				);
				$sub_cats = get_categories( $args2 );
				if($sub_cats) {
					foreach($sub_cats as $sub_category) {
						echo  $sub_category->name ;
					}   
				}
			}       
		}
	}
	/**/
?>

/* function call */

<div class="product_category col-lg-1 col-md-2">
     <?php if(function_exists("wooCommerceCategories")) wooCommerceCategories(); ?>
</div>


Google Live Map

<?php

/*
Template Name: map
*/

get_header();

?>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCPj2rrgRVKPap-cVS9_Wpd4fkBkXGF7fI&callback=myMap"></script>

<style>
	.common_page_container {border-top: 1px dashed #dddddd;margin:14px auto;padding: 24px 0;}
	.outletadd {padding: 0 0 0 3%;width:36%;}
	.store-col {float: left;margin: 0;}
	.store-col li {background:#f6f6f6;border: 1px solid #ddd;list-style: none;margin: 0 0 6px;padding: 3px 6px;}
	.store-col a {text-decoration: none; font-size: 13px;}
	#map-add {font-size: 13px; font-family: arial;}
	.map-add.store-col {float: left;margin: 0px;width:100%;}
	#MapCanvas {margin: 0;  max-width: 100%;min-height:380px;min-width: 300px;padding: 0;}
</style>

<script type="text/javascript">
	function updateMap(selectControl){ 
	    switch(selectControl){
			case 'Shimanto': 
			  initialize(23.738143,90.376614, "1st Floor, Road no-2, Dhanmondi, Dhaka<br/>Phone:+8802-8618890");
			  addressChange("Shimanto Square: <br/> 1st Floor, Road no-2, Dhanmondi, Dhaka <br/>Mobile:+88-01730068075");
			  break; 
			  
			case 'Mohammadpur':
			  initialize(23.76508,90.358429, "Shop No. 223-224, Toyko Square, Japan Garden City <br/>Mobile:+88-01730068069");
			  addressChange("Mohammadpur: <br/>Shop No. 223-224, Toyko Square, Japan Garden City <br/>Mobile:+88-01730068069");
			  break;
		}
	}   


	function initialize(lat,Lng,titletxt) { 
	    var mapOptions = {
	      center: new google.maps.LatLng(lat,Lng),
	      zoom: 17
	    };

	    var map = new google.maps.Map(document.getElementById("MapCanvas"),mapOptions);
		
		var marker = new google.maps.Marker({
			position: new google.maps.LatLng(lat,Lng),
			map: map,
			icon: 'http://labs.google.com/ridefinder/images/mm_20_red.png'
			//title: 'Rang'
		});

		var infowindow = new google.maps.InfoWindow({
		  content: titletxt,
		  zIndex: 990,
		});

		infowindow.open(map,marker);
	}

	function addressChange(add){
		document.getElementById('map-add').innerHTML = add;	
	}

	jQuery(document).ready( function($) {
		google.maps.event.addDomListener(window, 'load', initialize(24.1263456,90.3802059, "269-272 Tejgaon I/A Dhaka-1208, Bangladesh <br/>Tel: +88 02-8870616, 8870631<br/>"),check);	
	});
		
</script>



<div class="common_page_container">
	<div class="selectoutlet store-col">
		<ul>
			<li><a href="javascript:;" rel="Shimanto" onclick="updateMap(this.rel)">&nbsp; Shimanto Square</a></li>
			<li><a href="javascript:;" rel="Mohammadpur" onclick="updateMap(this.rel)">&nbsp; Mohammadpur</a></li>
			
		</ul>
		<!--<form>
			<select name="mapchange"  onchange="updateMap(this.options[this.selectedIndex].value)">
				<option value="Basundhara">&nbsp; Basundhara City</option>
				<option value="pink_city">&nbsp; Pink City</option>
				<option value="jamuna_future">&nbsp;Jamuna Future Park 1</option>
				<option value="jamuna_future2">&nbsp;Jamuna Future Park 2</option>
				
			</select>
		</form> -->
	</div>
	<div class="outletadd store-col">
		<div id="map-add">269-272 Tejgaon I/A Dhaka-1208, Bangladesh <br/>Tel: +88 02-8870616, 8870631<br/>E-mail: info@energypac-fashions.com</div>
	</div>
	<div class="map-add store-col">
		<div id="MapCanvas"></div>
	</div>
	<div class="clearer"></div>
</div>


<?php 
get_footer(); 

?>

Image uploading Problem

|| File is empty. Please upload something more substantial. This error could also be caused by uploads being disabled in your php.ini or by post_max_size being defined as smaller than upload_max_filesize in php.ini file

|| solved: Go to the file directory public_html wp-admin then put the php.ini file, and include following code


upload_max_filesize = 64M;
post_max_size = 32M;
safe_mode = off;