Skip to content

Instantly share code, notes, and snippets.

View developer-anuragsingh's full-sized avatar

Anurag Singh developer-anuragsingh

  • Cendyn
  • Gurugram
View GitHub Profile
<?php
// Add new custom hierarchical taxonomy with oops ways
add_action( 'init', 'new_hierarchical_taxonomy_type_for_cpt' );
function new_hierarchical_taxonomy_type_for_cpt() {
$post_type = 'job-opening';
$all_taxonomy = array('Department','Nature of Job', 'Qualification', 'Age', 'Location', 'Experience', 'CTC');
foreach ($all_taxonomy as $single) {
$single = ucwords(strtolower(preg_replace('/\s+/', ' ', $single) ));
$('.dropdown-toggle').click(function() {
var location = $(this).attr('href');
window.location.href = location;
return false;
});
<?php
// Setup Connection
$server = 'localhost'; $username = 'root'; $password = '';
# Connect to server
$conn = new MySQLi ($server, $username, $password);
if($conn->connect_error) {
die ('Connection Failed : ' . $conn->connect_error);
}
echo 'Connected to server.<br/>';
?>
add_filter('widget_text','execute_php',100);
function execute_php($html){
if(strpos($html,"<"."?php")!==false){
ob_start();
eval("?".">".$html);
$html=ob_get_contents();
ob_end_clean();
}
return $html;
}
// Override the default WP template system
add_filter('template_include', 'taxonomy_template');
function taxonomy_template( $template ){
if( is_tax('YOUR_TAXONOMY_NAME')){
$template = plugin_dir_path( __FILE__ ) .'/templates/taxonomy-YOUR_TAXONOMY_NAME.php';
}
return $template;
}
function as_custom_taxonomy_dropdown( $taxonomy ) {
$terms = get_terms( $taxonomy );
if ( $terms ) {
printf( '<select name="%s" class="postform">', esc_attr( $taxonomy ) );
foreach ( $terms as $term ) {
printf( '<option value="%s">%s</option>', esc_attr( $term->slug ), esc_html( $term->name ) );
}
print( '</select>' );
}
}
// Add post type link in Yoast Breadcrumbs for single page
add_filter( 'wpseo_breadcrumb_links', 'my_wpseo_breadcrumb_links' );
function my_wpseo_breadcrumb_links( $links ) {
if ( is_single() ) {
$cpt_object = get_post_type_object( get_post_type() );
if ( ! $cpt_object->_builtin ) {
$landing_page = get_page_by_path( $cpt_object->rewrite['slug'] );
array_splice( $links, -1, 0, array(
array(
add_action('admin_head-nav-menus.php', 'wpclean_add_metabox_menu_posttype_archive');
function wpclean_add_metabox_menu_posttype_archive() {
add_meta_box('wpclean-metabox-nav-menu-posttype', 'Custom Post Type Archives', 'wpclean_metabox_menu_posttype_archive', 'nav-menus', 'side', 'default');
}
function wpclean_metabox_menu_posttype_archive() {
$post_types = get_post_types(array('show_in_nav_menus' => true, 'has_archive' => true), 'object');
if ($post_types) :
/** Error reporting */
global $wpdb;
$wpdb->show_errors();
// For WordPress Multisite, you must define the DIEONDBERROR constant for database errors to display
define( 'DIEONDBERROR', true );
/** Error reporting */
$table = $wpdb->prefix . "report_performance";
$charset_collate = $wpdb->get_charset_collate();
$createTable = "CREAT TABLE IF NOT EXISTS $table (