Load all category posts in one template with format ‘posts-of-category-CatSlug’

To load all the category posts in same template file add the below hook to functions.php file :

function load_cat_parent_template(){
global $post;
$catsArr = array(‘posizioni-aperte’);
$cat = get_the_category($post->ID);
$template = TEMPLATEPATH . “/posts-of-category-“.$cat[0]->slug.”.php”;
load_template( dirname( __FILE__ ) . “/child-of-category-“.$cat[0]->slug.”.php” );


Add page parent class to subpage parent page in nav menu

To add class current to current sub page parent in top nav menu or any other nav menu add the below hook to functions.php file:

function add_class_to_wp_nav_menu($classes){
global $wp_query;
$post = $wp_query->post;
$pageMenuID = $post->post_parent;
$menu_items = wp_get_nav_menu_items(‘top menu’);
foreach($menu_items as $page) {
if( $page->post_parent == $pageMenuID){
$currentMenuItem = $page->ID;
$parentArr = get_page_by_path(‘lavora-con-noi’);
if( $page->post_parent == $parentArr->ID){
$currentMenuItem = $page->ID;

// add the current page class to a specific menu item (replace ###).
if (in_array(‘menu-item-‘.$currentMenuItem, $classes)){
$classes[] = ‘current-menu-item current_page_parent’;
return $classes;

Stop WordPress from adding p tags and removing line break

The hook to keep line break and  convert newline characters to BR tags “<br/>” also keep the redundant BR tags like “<br/> <br/>”  in editor of wordpress, just add the below hook in functions.php :


function tinymce_config( $init ) {
// Don’t remove line breaks
$init[‘remove_linebreaks’] = false;
// Convert newline characters to BR tags
$init[‘convert_newlines_to_brs’] = true;
// Do not remove redundant BR tags
$init[‘remove_redundant_brs’] = false;
// Pass $init back to WordPress
return $init;
add_filter(‘tiny_mce_before_init’, ‘tinymce_config’);