Skip to content

Instantly share code, notes, and snippets.

@junaidtk
junaidtk / New post type and taxonomy creation in WP
Last active January 17, 2019 17:07
WP Post type creation from function.php
For creating a new post types in wordpress admin panel we can use below function in init hook.
function theme_posttype() {
register_post_type('portfolio', array('label' => 'Works',
'description' => '',
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'capability_type' => 'page',
'hierarchical' => false,
@junaidtk
junaidtk / Check javascript variable contain a valid data
Created January 16, 2019 10:03
Check a javascript variable is valid one
In javascript, to check a variable contain a valid data or not, we can use the below code.
var value;
if(value){
// do something
}
If the variable doesn't contain a valid value it may have following 6 type of content.
This checking will valid if the variable is already defined.
@junaidtk
junaidtk / Display all hooks used in an WordPress page
Last active July 2, 2019 13:19
Show all hooks in the WP page
This code will display all hooks used in a page for wordpress website.
$debug_tags = array();
add_action( 'all', function ( $tag ) {
global $debug_tags;
if ( in_array( $tag, $debug_tags ) ) {
return;
}
echo "<pre>" . $tag . "</pre>";
$debug_tags[] = $tag;
@junaidtk
junaidtk / Step to configure woocommerce Sandbox checkout
Last active January 1, 2019 06:12
Woocommerce checkout using Paypal sandbox
For setting up the paypal checkout in woocommerce, we must have a paypal account.
The following are the steps to test paypal sandbox checkout in the woocommerce.
1. first we need to create a paypal account.
2. Then we goes to the https://developer.paypal.com/ page and check the sandbox area. Where we can see the buyer account and facilitator account.
3. Here we can add new buyer and facilitator account if required.
@junaidtk
junaidtk / Form Tips
Created November 29, 2018 07:40
Form Handling
if(isset($_POST['submit'])){
var_dump($_POST);
}
?>
<form method="post">
<input type="test" name="test">
<input type="test2" name="test2">
<div class="ttt" style="display: none;">
<input type="j1" name="j1" value="ttt">
<input type="j2" name="j2" value="yyy">
@junaidtk
junaidtk / Add admin user through code
Created November 13, 2018 17:55
How to add new admin user through the code snipppets
We can add new admin user by using below code. it will be helpfull if we forget the admin details of the website.
add_action('init', 'add_new_admin_user');
function add_new_admin_user() {
$username = 'testuser';
$email = '[email protected]';
$password = 'password';
$user_id = username_exists( $username );
if ( !$user_id && email_exists($email) == false ) {
@junaidtk
junaidtk / Pot file Creation
Last active September 22, 2022 07:03
How to create pot file for the plugin or theme
Step: 1
-----------
Download the WordPress i18n tools directory from SVN using the following command.
svn co http://develop.svn.wordpress.org/trunk/tools/
It will be executed from the website root directory of wordpress. So your wordpress directory contain additional folder tools.
Step: 2
-------------
@junaidtk
junaidtk / How to get Terms of a Post
Created October 23, 2018 16:55
Get the terms of a POST with ID
This function is used for getting the terms assinged for the post. This can bve used for the filter desing in the front like masonry
and isotop filtering in front end desing.
$terms = get_the_terms( $post->ID , array( 'taxonomy-name') );
$cat_app = '';
$cat_name = '';
foreach ($terms as $key => $cat) {
@junaidtk
junaidtk / WP Query Loop
Created October 23, 2018 16:46
Wordpress Post Query for displaying post details in front end
To query a post type in the wordpress template or in wordpress fornt end. Please use the following code snippets.
$args = array(
'post_type' => 'post',
'post_per_page' => 5,
'order' => 'ASC',
);
$the_query = new WP_Query($args);
@junaidtk
junaidtk / Submitting a form with button and input type
Created October 23, 2018 15:52
Use of <button type="submit"> and <input type="submit">
The form can be submitted to the browser by using button and input tag.
But we need to know which one is better for the form.
Diffrence between the <button type="submit"> and <input type="submit"> is, Input type can hold only specified text inside the value attribute.
But the <button type="submit"></button> can hold any type of data, can add html content in the button tag,
The button type is newer than input, so some older browser (eg: IE 6 ) dosn't support this tag.
In almost all modern browser will support button.