Custom Pagination in wp

Add custom pagination in wordpress

pagination
Continue reading “Custom Pagination in wp”

Get Id By Slug Or Slug By Id WP

get id by using slug

paste this function in function.php

function get_id_by_slug($page_slug) {
	$page = get_page_by_path($page_slug);
	if ($page) {
		return $page;
	} else {
		return null;
	}
}

example:
get_id_by_slug(‘about-us’);

get slug by id

global $post;
$slug = get_post( $post )->post_name;
echo $slug;

Create Short Code with Multiple attributes

We are going to add short code and create some of its attribute

We want to call post data on different pages with different categories and number of posts to show
also we can set post type

add this code in function.php


// This is a function for shortcode 
function custom_shortcode() {
     return 'hi i am short code function';
}

add_shortcode( 'shortcode', 'custom_shortcode' );

call this by using [shortcode]

Continue reading “Create Short Code with Multiple attributes”

Add Category or Tags For Pages

We have function that adds an already registered taxonomy to a custom object type.
Suppose we need to add the same categories and tags we use with posts to our Pages.

Here’s how we do it:

register_taxonomy_for_object_type( 'category', 'post' );
register_taxonomy_for_object_type( 'post_tag', 'post' );

Continue reading “Add Category or Tags For Pages”

Remove Junk From Head

Place the following code in your functions.php

remove_action('wp_head', 'rsd_link'); // remove really simple discovery link
remove_action('wp_head', 'wp_generator'); // remove wordpress version
remove_action('wp_head', 'feed_links', 2); // remove rss feed links (make sure you add them in yourself if youre using feedblitz or an rss service)
remove_action('wp_head', 'feed_links_extra', 3); // removes all extra rss feed links
remove_action('wp_head', 'index_rel_link'); // remove link to index page
remove_action('wp_head', 'wlwmanifest_link'); // remove wlwmanifest.xml (needed to support windows live writer)
remove_action('wp_head', 'start_post_rel_link', 10, 0); // remove random post link
remove_action('wp_head', 'parent_post_rel_link', 10, 0); // remove parent post link
remove_action('wp_head', 'adjacent_posts_rel_link', 10, 0); // remove the next and previous post links
remove_action('wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0 );
remove_action('wp_head', 'wp_shortlink_wp_head', 10, 0 );
remove_action('wp_head', 'print_emoji_detection_script', 7 ); 
remove_action('wp_print_styles', 'print_emoji_styles' );
remove_action('wp_head', 'wp_resource_hints', 2); // Remove DNS Prefetch Link

Custom Taxonomy

Create Custom Taxonomy Reuseable Function

Just paste this function in function.php

// Add new taxonomy
function taxoFunc($taxoName, $postType, $prefix){
	$menuName = ucwords($taxoName);
	$taxoName = strtolower(str_replace( ' ', '_', $taxoName));
	$labels = array(
		'name'              => _x( $menuName, 'taxonomy general name' ),
		'singular_name'     => _x( $menuName, 'taxonomy singular name' ),
		'search_items'      => __( 'Search' ),
		'all_items'         => __( 'All' ),
		'parent_item'       => __( 'Parent' ),
		'parent_item_colon' => __( 'Parent:' ),
		'edit_item'         => __( 'Edit' ),
		'update_item'       => __( 'Update' ),
		'add_new_item'      => __( 'Add New' ),
		'new_item_name'     => __( 'New Name' ),
		'menu_name'         => __( $menuName ),
	);

	$args = array(
		'hierarchical'      => true,
		'labels'            => $labels,	
		'show_ui'           => true,
		'show_admin_column' => true,
		'query_var'         => true,
		'rewrite'           => array( 'slug' => $taxoName, 'with_front' => false ),
	);

	register_taxonomy( $prefix.$taxoName, $postType, $args );
	
}

Now just place this line and change values according your post type

taxoFunc('Category', 'PostTypeName', 'c_');

You can call this function multiple time with different values…

Example:

taxoFunc('Category 1', 'PostTypeName', 'c_');
taxoFunc('Category 2', 'PostTypeName', 'c_');
taxoFunc('Category 3', 'PostTypeName', 'c_');