How To Define A Template In WordPress
The following lines of code will let you define a template in WordPress.
1 2 3 4 5 |
<?php /* Template Name: Snarfer */ ?> |
Snippet Source/Credit: WordPress.org
How To Deregister All In One Event Calendar In WordPress
The following snippet will let you deregister all in one event calendar in WordPress.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
// clean up unwanted JS scripts function my_print_scripts(){ if ( !is_admin() ) { wp_deregister_script('jquery'); wp_deregister_script('ai1ec_requirejs'); } } add_action('wp_print_scripts', 'my_print_scripts'); // clean up unwanted CSS function my_print_css() { if ( !is_admin() ) { wp_deregister_style('ai1ec-general'); wp_deregister_style('ai1ec-event'); wp_deregister_style('ai1ec-calendar'); } } add_action('wp_print_styles', 'my_print_css'); |
Snippet Source/Credit: Ditscheri.com
How To Disable Sidebars And Widgets On Page Template In WordPress
The following snippet will let you disable sidebars and widgets on page template in WordPress.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
<?php /* Disables widget areas. */ add_filter( 'sidebars_widgets', 'remove_sidebars' ); function remove_sidebars( $sidebars_widgets ) { global $wp_query; if ( is_singular() ) { $template = get_post_meta( $wp_query->post->ID, "_wp_{$wp_query->post->post_type}_template", true ); // Disables all widgets if ( preg_match("/(-no-widgets.php)$/i", $template ) ) $sidebars_widgets = array( true ); // Disables 'primary' & 'secondary' sidebars widgets if ( preg_match("/(-no-sidebars.php)$/i", $template ) ) $sidebars_widgets['primary'] = false; $sidebars_widgets['secondary'] = false; } return $sidebars_widgets; } ?> |
How To Echo Starting 20 Words Of Any Page In WordPress
The following snippet will let you echo starting 20 words of any page in WordPress.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
<?php $my_id = 22; // change to relevant page ID $post_id_5369 = get_post($my_id); $content = $post_id_5369->post_content; $content = apply_filters('the_content', $content); $content = str_replace(']]>', ']]>', $content); $words = explode(' ', $content); $i = 0; while ($i <= 20) { $short .= $words[$i] . ' '; $i++; } echo $short; ?> |
How To Get Image Path Relevant To Theme In WordPress
The following snippet will let you get image path relevant to theme in WordPress.
1 |
<?php bloginfo('template_directory'); ?>/ |