Enjoy.....!
How to hide a dive on url change using jQuery
Example of using this method
Labels:
JQuery
How to redirect login user on desire page in wordpress
Copy this and paste this code in functions.php
<?php
add_filter('login_redirect', '_catch_login_error', 10, 3);
function _catch_login_error($redir1, $redir2, $wperr_user)
{
if(!is_wp_error($wperr_user) || !$wperr_user->get_error_code()) return $redir1;
switch($wperr_user->get_error_code())
{
case 'incorrect_password':
case 'empty_password':
case 'invalid_username':
default:
wp_redirect(site_url().'/home-page/?error='.$wperr_user->get_error_code());
}
return $redir1;
}
?>
Labels:
wordpress
how to make make shortcode of page/post in wordpress
Copy and paste this code in your function.php file
[postPage_include postidparam="1234"]
"1234" would be the WordPress ID of the Page you are
Method for use in post or page in template :-
echo do_shortcode( '[postPage_include postidparam="1234"]' );
<?php
function digwp_includeContentShortcode($atts) {
$thepostid = intval($atts[postidparam]);
$output = '';
query_posts("p=$thepostid&post_type=page");
if (have_posts()) : while (have_posts()) : the_post();
$output .= get_the_content($post->ID);
endwhile; else:
// failed, output nothing
endif;
wp_reset_query();
return $output;
}
// USAGE
/* In the post content, you can use
[postPage_include postidparam="1234"]
"1234" would be the WordPress ID of the Page you are
trying to include */
add_shortcode("postPage_include", "digwp_includeContentShortcode");
?>
Method for use in post or page in back-end :- [postPage_include postidparam="1234"]
"1234" would be the WordPress ID of the Page you are
Method for use in post or page in template :-
echo do_shortcode( '[postPage_include postidparam="1234"]' );
Labels:
wordpress
Create a custom widget and call it by using shortcode in wordpress
Copy code in functions.php
Now in Post/Page content, you can use the widget just by referencing it by name:
[widget widget_name="Your_Custom_Widget"]
enjoy!!
<?php
function widget($atts) {
global $wp_widget_factory;
extract(shortcode_atts(array(
'widget_name' => FALSE
), $atts));
$widget_name = wp_specialchars($widget_name);
if (!is_a($wp_widget_factory->widgets[$widget_name], 'WP_Widget')):
$wp_class = 'WP_Widget_'.ucwords(strtolower($class));
if (!is_a($wp_widget_factory->widgets[$wp_class], 'WP_Widget')):
return ''.sprintf(__("%s: Widget class not found. Make sure this widget exists and the class name is correct"),''.$class.'').'
';
else:
$class = $wp_class;
endif;
endif;
ob_start();
the_widget($widget_name, $instance, array('widget_id'=>'arbitrary-instance-'.$id,
'before_widget' => '',
'after_widget' => '',
'before_title' => '',
'after_title' => ''
));
$output = ob_get_contents();
ob_end_clean();
return $output;
}
add_shortcode('widget','widget');
?>
Usage
Now in Post/Page content, you can use the widget just by referencing it by name:
[widget widget_name="Your_Custom_Widget"]
enjoy!!
Labels:
wordpress
use shortcodes within a WordPress Text widget
By default, WordPress shortcodes do not work within Text widgets. If you
need this functionality, it is quite easy to accomplish, simply follow
the steps below.
- Log into your WordPress Dashboard
- Under "Appearance" click "Editor"
- In the list of files on the right of the page, click "functions.php"
- At the bottom of the functions.php file, add the following code:
add_filter( 'widget_text', 'shortcode_unautop');
add_filter( 'widget_text', 'do_shortcode');Click "Update File" and your shortcodes should now work in your Text widgets!
Labels:
wordpress
how to make shortcode of custome field type in wordpress
1. Copy this php script in your functions.php
function field_scode($value){
global $post;
$name = $value['name'];
if(empty($name)) return;
return get_post_meta($post->ID,$name,true);
}
add_shortcode('my_shortcode','field_scode');
/* use this shortcode in your post or page or in template
exp:- [my_shortcode name="put_field_name_here"]
*/
function field_scode($value){
global $post;
$name = $value['name'];
if(empty($name)) return;
return get_post_meta($post->ID,$name,true);
}
add_shortcode('my_shortcode','field_scode');
/* use this shortcode in your post or page or in template
exp:- [my_shortcode name="put_field_name_here"]
*/
Labels:
wordpress
Php script for file download
1. PHP Script for image download you can make any file to to download
Paste this script in your file or save it download.php
<?php
$imageurl = filter_input(INPUT_GET, 'imageurl', FILTER_SANITIZE_URL);
// Clean the image URL to get the path and make sure the user is just getting an image.
$url_parsed = parse_url($imageurl);
$file = $_SERVER['DOCUMENT_ROOT'] .'/base-directory'. $url_parsed['path'];
print_r($file);
// Get the extension of the file.
$extension = substr(strrchr($file ,'.'), 1);
// Limit the extensions in this array to those you're allowing the user to download.
$allowed_extensions = array('jpg', 'jpeg', 'png', 'gif');
// Make sure the file requested is in your list of allowed extensions to make sure the user isn't downloading something other than an image.
if (in_array(strtolower($extension), $allowed_extensions)) {
if (file_exists($file)) {
header ('Content-type: octet/stream');
header ('Content-disposition: attachment; filename=' . basename($file) . ';');
header('Content-Length: ' . filesize($file));
ob_clean();
readfile($file);
}
}
?>
1. HTML Code
Paste this code in your html file
DownloadEnjoy......
Labels:
PHP
How to show costum sidebar in wordpress template
<?php /** * Template Name: Home Page Template */ get_header(); ?>
Labels:
wordpress
Make plugin using shortcode in wordpress to display database information
<?php
/**
* Plugin Name:user info
* Plugin URI: http://wordpress_aprai.org
* Description: this plugin will be display data from database you can use this shortcode any where
* Author:Arunendra Pratap rai
*/
function display()
{
global $wpdb;
$sql ="select * from `first_projectposts` where `post_type` = 'DisplayPost'";
$query = $wpdb->get_results($sql);
echo '| id | first name | Last name | email id | Password |
|---|---|---|---|---|
| '.$id.' | '.$fname.' | '.$lname.' | '.$email.' | '.$pass.' |
[short_code] In template use:-
<?php echo do_shortcode('[short_code]') ?>
Labels:
wordpress
Wordpress install and uninstall plugin table during activation and deactivation of plugin
<?php
/*
Plugin Name: sample plugin
Plugin URI: http://URI_Of_Page_Describing_Plugin_and_Updates
Description: This plugin is used to add youtube embeded video code and show video in widgets.
Version: 2.1
Author: Arunendra Pratap Rai
Author URI: http://URI_Of_The_Plugin_Author
License: A "Slug" license name e.g. GPL2
*/
register_activation_hook(__FILE__,'pro_install'); // table installation hook
register_deactivation_hook(__FILE__ , 'pro_uninstall' ); //table uninstallation hook
function pro_install()
{
global $wpdb;
$table = wp_."table_name";
$structure = "CREATE TABLE $table (
id INT(9) NOT NULL AUTO_INCREMENT,
fname VARCHAR(255) NOT NULL,
lname VARCHAR(255) NOT NULL,
UNIQUE KEY id (id)
);";
$wpdb->query($structure);
// Populate table
$wpdb->query("INSERT INTO $table(id,fname,lname)
VALUES('1', 'arunendra','Pratap rai')");
}
function pro_uninstall()
{
global $wpdb;
$table = wp_."table_name";
$structure = "drop table if exists $table";
$wpdb->query($structure);
}
?>
Labels:
wordpress
PHP Interview Question Answer
1) What is
PHP.?
PHP is a web
language based on scripts that allows developers to dynamically create
generated web pages.
2) What does
the initials of PHP stand for.?
PHP means
PHP: Hypertext Preprocessor.
3) Which
programming language does PHP resemble to.?
PHP syntax
resembles Perl and C
4) What does
PEAR stands for.?
PEAR means
“PHP Extension and Application Repository”. it extends PHP and provides a
higher level of programming for web developers.
5) What is
the actually used PHP version.?
Version 5 is
the actually used version of PHP.
6) How do
you execute a PHP script from the command line.?
Just use the
PHP command line interface (CLI) and specify the file name of the script to be
executed as follows:
1
|
php script.php
|
7) How to
run the interactive PHP shell from the command line interface.?
Labels:
PHP
Subscribe to:
Comments (Atom)