WordPress Cheat Sheet

Optimize Your Website For Search Engines Right Now

WordPress Cheat Sheet



Turbo WordPress Cheat Sheet

Popular WordPress Template Tags

<?php wp_list_pages('exclude=6&title_li=<h2>Pages</h2>'); ?>
<?php wp_list_pages('exclude=48,376,610,613,614,725&title_li=<h2>Pages</h2>'); ?>
<?php wp_list_categories('show_count=0&order=desc&title_li=<h2>Categories</h2>'); ?>
<?php wp_link_pages(array('before'=>'Pages: ', 'next_or_number'=>'number')); ?>
<?php wp_list_bookmarks(); // $post->post_title ?>
<?php wp_list_pages('title_li=&exclude=6'); ?>
<?php wp_get_archives('type=monthly'); ?>

Source

Exclude category from feeds

Add this to your functions.php file

// custom feed query
function customFeedquery($query) {
	if(is_feed()) {
		$query->set('cat','-8'); // exclude category 8
		return $query;
	}
}
add_filter('pre_get_posts', 'customFeedquery');

Source

Related Posts For Custom Post Type by Custom Taxonomy

<!-- begin custom related loop, isa -->
 
<?php 
 
// get the custom post type's taxonomy terms
 
$custom_taxterms = wp_get_object_terms( $post->ID, 'your_taxonomy', array('fields' => 'ids') );
// arguments
$args = array(
'post_type' => 'your_custom_post_type',
'post_status' => 'publish',
'posts_per_page' => 3, // you may edit this number
'orderby' => 'rand',
'tax_query' => array(
    array(
        'taxonomy' => 'your_taxonomy',
        'field' => 'id',
        'terms' => $custom_taxterms
    )
),
'post__not_in' => array ($post->ID),
);
$related_items = new WP_Query( $args );
// loop over query
if ($related_items->have_posts()) :
echo '<ul>';
while ( $related_items->have_posts() ) : $related_items->the_post();
?>
    <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php
endwhile;
echo '</ul>';
endif;
// Reset Post Data
wp_reset_postdata();
?>
<!-- end custom related loop, isa -->

Source: https://isabelcastillo.com/related-custom-post-type-taxonomy



SEO Tools For Mobile Device