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
@ShiponKarmakar
ShiponKarmakar / .htaccess
Last active January 23, 2024 02:20
Most Useful and Helpful .htaccess Code
#stop directory browsing
Options All -Indexes
# SSL Https active Force non-www
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
@TanvirAmi
TanvirAmi / cat-id.php
Created December 15, 2015 16:57
Sometimes we need current category id in a current page for various operation in wordpress. By the way we can get current category id in wordpress.
<?php
$categories = get_the_category();
$x = $categories[0]->cat_ID;
print_r($x);
?>
@ghalusa
ghalusa / youtube_id_regex.php
Created June 20, 2015 23:14
Extract the YouTube Video ID from a URL in PHP
<?php
// Here is a sample of the URLs this regex matches: (there can be more content after the given URL that will be ignored)
// http://youtu.be/dQw4w9WgXcQ
// http://www.youtube.com/embed/dQw4w9WgXcQ
// http://www.youtube.com/watch?v=dQw4w9WgXcQ
// http://www.youtube.com/?v=dQw4w9WgXcQ
// http://www.youtube.com/v/dQw4w9WgXcQ
// http://www.youtube.com/e/dQw4w9WgXcQ
// http://www.youtube.com/user/username#p/u/11/dQw4w9WgXcQ
@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";
}
@davidsneal
davidsneal / html-share-buttons.html
Last active December 12, 2023 13:18
HTML Share Buttons
<!-- I got these buttons from simplesharebuttons.com -->
<div id="share-buttons">
<!-- Buffer -->
<a href="https://bufferapp.com/add?url=https://simplesharebuttons.com&amp;text=Simple Share Buttons" target="_blank">
<img src="https://simplesharebuttons.com/images/somacro/buffer.png" alt="Buffer" />
</a>
<!-- Digg -->
<a href="http://www.digg.com/submit?url=https://simplesharebuttons.com" target="_blank">
<?php
/**
* http://webdeveloperswall.com/php/get-youtube-video-id-from-url
**/
function extractUTubeVidId($url){
/*
* type1: http://www.youtube.com/watch?v=9Jr6OtgiOIw
* type2: http://www.youtube.com/watch?v=9Jr6OtgiOIw&feature=related
* type3: http://youtu.be/9Jr6OtgiOIw
*/
@keichan34
keichan34 / php_stdclass_init.php
Created October 3, 2013 08:02
PHP stdClass initialization vs array-to-object typecast
<?php
$start = microtime(true);
for($i=0;$i<1000000;$i++) {
$a = new stdClass();
$a->hello = 'there';
}
$end = microtime(true);