Skip to content

Instantly share code, notes, and snippets.

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

Tanvir TanvirAmi

🏠
Working from home
View GitHub Profile
<?php
echo "Hello World";
?>
@TanvirAmi
TanvirAmi / force-title.php
Last active August 29, 2015 14:15
Will force to show the page title in woocommerce
<?php
function return_page_title() {
return true;
}
add_filter('woocommerce_show_page_title', 'return_page_title');
?>
@TanvirAmi
TanvirAmi / hit-counter.php
Created February 12, 2015 02:19
Post hit counter in wordpress
<?php
//In functions.php
function getHits($postID){
$hits_token = 'post_views_hits';
$hits = get_post_meta($postID, $hits_token, true);
if($hits==''){
delete_post_meta($postID, $hits_token);
add_post_meta($postID, $hits_token, '0');
return "0 View";
}
@TanvirAmi
TanvirAmi / .htaccess
Created April 25, 2015 00:37
icon support
<IfModule mod_headers.c>
<FilesMatch "\.(eot|font.css|otf|ttc|ttf|woff)$">
Header set Access-Control-Allow-Origin "*"
</FilesMatch>
</IfModule>
<?php
/*
* WordPress Breadcrumbs
* author: Dimox
* version: 2015.05.21
*/
function dimox_breadcrumbs() {
/* === OPTIONS === */
<?php
$show_after_p = 2;
$content = apply_filters('the_content', $post->post_content);
if(substr_count($content, '<p>') > $show_after_p)
{
$contents = explode("</p>", $content);
$p_count = 1;
foreach($contents as $content)
{
echo $content;
@TanvirAmi
TanvirAmi / exclude.php
Created October 16, 2015 13:33
Exclude posts from main wordpress loop.
<?php
add_action( 'pre_get_posts', 'wpsites_remove_posts_from_home_page' );
function wpsites_remove_posts_from_home_page( $query ) {
if( $query->is_main_query() && $query->is_home() ) {
$query->set( 'post__not_in', array(your_post_id) );
}
}
?>
@TanvirAmi
TanvirAmi / fixed-nav.js
Last active December 18, 2015 08:41
Navigation will be fixed at the top position at the time of scrolling. You have to change (#custom_nav_id) with your custom nav/div id.
jQuery(function($) {
// grab the initial top offset of the navigation
var sticky_navigation_offset_top = $('#custom_nav_id').offset().top;
// our function that decides weather the navigation bar should have "fixed" css position or not.
var sticky_navigation = function(){
var scroll_top = $(window).scrollTop(); // our current vertical position from the top
// if we've scrolled more than the navigation, change its position to fixed to stick to top, otherwise change it back to relative
@TanvirAmi
TanvirAmi / custom-excerpt.php
Created November 14, 2015 08:53
Filtering the default excerpt in wordpress post.
<?php
/**
* Control excerpt length.
*/
function custom_excerpt_length( $length ) {
return 15;
}
add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );
?>
@TanvirAmi
TanvirAmi / exceprt-more.php
Created November 14, 2015 08:56
Change the "more" text of wordpress excerpt.
<?php
/**
* Change the excerpt more string.
* @param string $more
* @return string
*/
function custom_excerpt_more( $more ) {
return '&hellip;';
}
add_filter( 'excerpt_more', 'custom_excerpt_more' );