Skip to content

Instantly share code, notes, and snippets.

@junaidtk
junaidtk / How to edit
Last active July 9, 2018 17:43
How to configure htaccess file
Htaccess file is used to redirect the url rewriting and also for making the SEO friendly URL.
Commomly used htaccess codes are listed below.
RewriteEngine on # This is to make the rewrite engin ON
RewriteCond and RewriteRule: => are the commonly used commands to write the htaccess codes.
"RewriteRule" :- It will redirect the current url to the required url.
"RewriteRule ^test/?$ test.php [NC,L] " # it will redirect to the test to the test.php
@junaidtk
junaidtk / php.ini
Created July 10, 2018 06:25
To increase max upload size you can use following methods
1) You can use the .htaccess file to increase the file upload size of the server.
Add below codes in the server .htaccess file of the site
php_value upload_max_filesize 128M
php_value post_max_size 128M
php_value max_execution_time 300
php_value max_input_time 300
2)if htaccess trick does't work you edit the php.ini file of the server.
@junaidtk
junaidtk / gist:f64ff6a8ccfa996593053df73691eddc
Created October 3, 2018 14:36
Convert http request to https
We need to add the below code in between <IfModule mod_rewrite.c>
# Rewrite HTTP to HTTPS
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*) https://%{SERVER_NAME}/$1 [R,L]
The above code will load the https url instead of http
@junaidtk
junaidtk / WP REST API
Created October 17, 2018 17:03
How to add meta field to REST API Response of a WordPress Posts using register_meta ?
You can use two methods for adding the new meta field to Rest API. By using register_meta() function and register_rest_field() function.
1)register_meta() function.
By using this function you can add additional meta key to API response by adding the 'show_in_rest' => true, parameter to arguments.
eg:
$object_type = 'post';
$args1 = array( // Validate and sanitize the meta value.
// Note: currently (4.7) one of 'string', 'boolean', 'integer',
// 'number' must be used as 'type'. The default is 'string'.
@junaidtk
junaidtk / WP REST API register_rest_field().
Created October 17, 2018 17:15
How to add meta field to REST API Response of a WordPress Posts using register_rest_field?
You can use the register_rest_field() function to add additional meta key to the REST API
eg:
add_action( 'rest_api_init', 'create_api_posts_meta_field' );
function create_api_posts_meta_field() {
// register_rest_field ( 'name-of-post-type', 'name-of-field-to-return', array-of-callbacks-and-schema() )
register_rest_field( 'post', 'banner_image', array(
'get_callback' => 'get_post_meta_for_api',
@junaidtk
junaidtk / WP REST API Custom End Point
Created October 18, 2018 17:45
REST API greeting using custom end point
We can create custom end point by using the register_rest_route() function. This function is need to call in rest_api_init hooks.
For this function register_rest_route(), the first argument is namespace, 2nd one is resource path or resource base and 3rd one is array option.
In array optuion we specify what method the end point can use and what call back is happen when an end point is matched.
/**
* This is our callback function that embeds our phrase in a WP_REST_Response
*/
function prefix_get_endpoint_phrase() {
@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.
@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 / 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 / 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
-------------