Category Archives: Theme

Register Sidebars


/*
* Legal Main Sidebar
*/

function legal_widgets_init() {

register_sidebar(array(
'name' => __('Main Sidebar', 'legal'),
'id' => 'sidebar-1',
'description' => __('Main sidebar that appears on the right.', 'legal'),
'before_widget' => '<aside id="%1$s" class="sidebar-widget widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
));

register_sidebar(array(
'name' => __('Footer Area One', 'legal'),
'id' => 'footer-1',
'description' => __('Footer Area One that appears on footer.', 'legal'),
'before_widget' => '<aside id="%1$s" class="footer-widget widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h3>',
'after_title' => '</h3>',
));

register_sidebar(array(
'name' => __('Footer Area Two', 'legal'),
'id' => 'footer-2',
'description' => __('Footer Area Two that appears on footer.', 'legal'),
'before_widget' => '<aside id="%1$s" class="footer-widget widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h3>',
'after_title' => '</h3>',
));

register_sidebar(array(
'name' => __('Footer Area Three', 'legal'),
'id' => 'footer-3',
'description' => __('Footer Area Three that appears on footer.', 'legal'),
'before_widget' => '<aside id="%1$s" class="footer-widget widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h3>',
'after_title' => '</h3>',
));

register_sidebar(array(
'name' => __('Footer Area Four', 'legal'),
'id' => 'footer-4',
'description' => __('Footer Area Four that appears on footer.', 'legal'),
'before_widget' => '<aside id="%1$s" class="footer-widget widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h3>',
'after_title' => '</h3>',
));
}

add_action('widgets_init', 'legal_widgets_init');



Display:


<div class="col-md-3 col-sm-6">
<?php if (is_active_sidebar('footer-1')) { ?>
<div class="footer-widget">
<?php dynamic_sidebar('footer-1'); ?>
</div>
<?php } ?>
</div>

Create Child theme in wordpress

style.css



/*
 Theme Name:     Twenty Sixteen Child Theme
 Template:       twentysixteen
*/

functions.php


add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
function theme_enqueue_styles() {
    wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
    //wp_enqueue_style( 'child-style',get_stylesheet_directory_uri() . '/style.css',array('parent-style'));
}

main post under sub posts by page attribute

functions.php


/* custom post type trove */

function trove_custom_init() {
$labels = array(
'name' => __('Treasure Trove','themename'),
'singular_name' => __('trove','themename'),
'add_new' => __('Add New','themename'),
'add_new_item' => __('Add New Treasure Trove','themename'),
'edit_item' => __('Edit Treasure Trove','themename'),
'new_item' => __('New Treasure Trove','themename'),
'all_items' => __('All Treasure Trove','themename'),
'view_item' => __('View Treasure Trove','themename'),
'search_items' => __('Search Treasure Trove','themename'),
'not_found' => __('No Treasure Trove found','themename'),
'not_found_in_trash' => __('No Treasure Trove found in Trash','themename'),
'parent_item_colon' => "",
'menu_name' => __('Treasure Trove','themename')
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'trove' ),
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => true,
'menu_position' => null,
'supports' => array( 'title', 'editor','thumbnail','page-attributes'),
);
register_post_type( 'trove', $args );
}
add_action( 'init', 'trove_custom_init' );

Display Posts


<div class="blog-details single">
<?php
global $post;
$troveargs = array(
'paged' => $paged,
'post_type' => 'trove',
'post_status' => 'publish',
'order' => 'ASC',
'post_parent' => 0
);
$trove_query = new WP_Query($troveargs);

while ( $trove_query->have_posts() ) : $trove_query->the_post();
//if ($post->post_parent == 0) {
?>
<div class="col-md-12 no-padding trovebox">
<h2>
<?php the_title(); ?>
</h2>
<p>
<?php the_content(); ?>
</p>
</div>
<?php
/* Start Second Loop of sub procuct listed under main product */
$troveargs_sub = array(
'paged' => $paged,
'post_type' => 'trove',
'post_status' => 'publish',
'order' => 'ASC',
'post_parent' => $post->ID
);
$trove_query_sub = new WP_Query($troveargs_sub);
while ( $trove_query_sub->have_posts() ) : $trove_query_sub->the_post();
//echo wp_get_post_parent_id( $post_ID );
?>
<div class="col-md-12 no-padding trovebox">
<h4>
<?php the_title(); ?>
</h4>
</div>
<?php endwhile;
/* End Second Loop*/
?>
<?php endwhile; ?>
</div>

Image auto crop with defined size

Functions.php

// Crop image for home page posts

add_image_size('legal-thumbnail-image', 420, 247, true);

Display


<?php $legal_image = wp_get_attachment_image_src(get_post_thumbnail_id(get_the_ID()), 'legal-thumbnail-image', true); ?>
<a href="<?php the_permalink(); ?>"><img class="img-responsive" src="<?php echo esc_url($legal_image[0]); ?>" width="<?php echo $legal_image[1]; ?>" height="<?php echo $legal_image[2]; ?>" alt="<?php the_title(); ?>" /></a>

Display plugin on frontend side if is active

/* if booking plugin is active */
function legalattorneys_shortcode(){
include_once( ABSPATH . ‘wp-admin/includes/plugin.php’ );
if(is_plugin_active(‘fastbook-responsive-appointment-booking-and-scheduling-system/fastbook.php’)) {
echo do_shortcode(‘[fastbook]’);
}
}

/* Display any where */

<?php legalattorneys_shortcode(); ?>

Sanitation(validation) in wordpress

Backend side:
For url and image:  esc_url_raw();
For text:           sanitize_text_field();
For email:          sanitize_email();

Frontend side:
For url and image:   esc_url();
For email and text:  esc_attr();

=========================================
/* Validation for uploaded image */

function advent_image_validation($advent_imge_url) {
$advent_filetype = wp_check_filetype($advent_imge_url);

$advent_supported_image = array(‘gif’, ‘jpg’, ‘jpeg’, ‘png’, ‘ico’);

if (in_array($advent_filetype[‘ext’], $advent_supported_image)) {
return $advent_imge_url;
} else {
return ”;
}
}
/* sanitation */
advent_image_validation(esc_url_raw($input[‘logo’]));

%d bloggers like this: