Saturday, June 1, 2013

Website visit count in wordpress


We can track wordpress visit count using function.php. Just use the following function in function.php
<?php
function visit_count()
{
// just increment and display a counter at the bottom of each page
if(!isset($_SESSION['hit_count']))
{
$count=1+intval(get_option('site_visit_count'));
update_option('site_visit_count',$count);
}
$_SESSION['hit_count']=$count=get_option('site_visit_count');
$count=number_format($count);
echo << $count
HTML_CODE;
}
?>
Call function "visit_count()" in our site to display the total number of visitors in your site. Sometimes session is disabled in your wordpress site, then the code will not work perfectly. We need to enable session in wordpress. Check the following link to know how to enable session in wordpress.
Enable session in wordpress

Enable session in wordpress


Normally session will not work in wordpress and we need to enable session. We can enable it by initializing. Function for initializing session is
function init_sessions() {
if (!session_id()) {
session_start();
}
}
add_action('init', 'init_sessions');

Just copy the code and paste it in your function.php

Friday, May 24, 2013

Prevent form resubmitting using php


Simple method for preventing form resubmission using php.

<?php
if(!isset($_SESSION))
{
session_start();
}
if($_POST)
{
if($_SESSION['token'] == $_POST['token'])
{
echo $_POST['txt'];
echo '</br>Submitting';
// Place form action code here
}
else
{
echo 'Re Submitting';
}
}
$_SESSION['token'] = $token = rand();
?>

<form name="frm" action="" method="post" >
<input type="text" name="txt" />
<input type="hidden" name="token" value="<?php echo $token; ?>" />
<input type="submit" />
</form>

Monday, May 13, 2013

Add QR Code for wordpress post

To add QR code for wordpress post, use the following code


    < img src="http://api.qrserver.com/v1/create-qr-code/?size=200x200&data="<?php the_permalink() ?>" alt="QR Code for <?php the_title(); ?>" />

Sunday, April 14, 2013

Remove Version Number from Wordpress

By default WordPress displays version number publicly on your Website. But sometimes this might be a security risk for WordPress site. Hackers can easily identify the WordPress version. To prevent this, just remove WordPress version from the site.

Just add the following function in function.php to remove the version number.


function remove_wp_version() {
return '';
}

add_filter('the_generator', 'remove_wp_version');

Change WP Login Logo and URL using function.php

To replace wordpress default login logo with a custom one, just add following function in function.php



function wp_custom_login_logo() {
    echo '<style type="text/css">
        h1 a { background-image:url('.get_bloginfo('template_directory').'/images/your-logo.png) !important; }
    </style>';
}

add_action('login_head', 'wp_custom_login_logo');

To customize wordpress login url, add following function in function.php


function wp_custom_login_url() {
  return site_url();
}

add_filter( 'login_headerurl', 'my_custom_login_url', 10, 4 );


Thursday, March 21, 2013

WordPress 3.5 media upload customized form


You can use WordPress image upolader in your theme, theme option or plugin.  You can find out detail from this post. You can download demo files from the link placed below.

Follow the steps mentioned here


Include following jquery in your page

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> <script type="application/javascript">
jQuery(document).ready(function($){
var _custom_media = true;
 _orig_send_attachment = wp.media.editor.send.attachment;
 $('#btn_upload').click(function(e) {
var send_attachment_bkp = wp.media.editor.send.attachment;
_custom_media = true;
wp.media.editor.send.attachment = function(props, attachment){
 if ( _custom_media ) {
 $("#txt_imageurl").val(attachment.url);
 } else {
 return _orig_send_attachment.apply( this, [props, attachment] ); }; }
 wp.media.editor.open(this); return false; }); });
 </script>

Enable following wordpress jqueries

<?php if(function_exists( 'wp_enqueue_media' )){
wp_enqueue_media();
 }else{
wp_enqueue_style('thickbox');
wp_enqueue_script('media-upload');
wp_enqueue_script('thickbox'); }?>

Create elements for uploading
<input type="text" name="txt_imageurl" id="txt_imageurl" />
<input type="button" class="button" name="btn_upload" id="btn_upload" value="Upload" />

Download Demo from GitHub Click Here