Mark menu item as current-menu-item for category

I use this functions. First of all, you have to add some custom class to your menu item (allow class input in Screen options, it’s not visible by default). function mark_menu_item_as_active($classes, $item) { if( in_array(‘my-custom-class’,$classes) && ( is_category(‘my-category’) /* OR …*/ ) ) { $classes[] = ‘current-menu-item’; } return $classes; } add_filter(‘nav_menu_css_class’, ‘mark_menu_item_as_active’, 10, 2); … Read more

Set a static front-page as a landing page programmatically

You can do it by targeting get_option(‘show_on_front’); some code which could help would be: function themename_after_setup_theme() { $site_type = get_option(‘show_on_front’); if($site_type == ‘posts’) { update_option( ‘show_on_front’, ‘page’ ); update_option( ‘page_for_posts’, ‘page-name’ ); } } add_action( ‘after_setup_theme’, ‘themename_after_setup_theme’ ); This will run on theme activation only, remember to change the page-name to the page you want … Read more

Simple way to get two language WP site

You can use below code for translating strings: add_filter(‘gettext’, ‘translate_text’); add_filter(‘ngettext’, ‘translate_text’); function translate_text($translated) { $translated = str_ireplace(‘Choose an option’, ‘Select’, $translated); $translated = str_ireplace(‘Original Text’, ‘Your Replacment Text’, $translated); return $translated; } But I have no idea for translating complex contents. I know you don’t want to use plugins but as my research, we … Read more

Implement content-nosidebar.php / content-leftsidebar.php

Add this in your functions.php if( !function_exists( ‘my_custom_widgetize_theme’ ) ){ add_action ( ‘after_setup_theme’, ‘my_custom_widgetize_theme’, 10 ); function my_custom_widgetize_theme(){ register_sidebar(array( ‘name’ => ‘My SideBar’, ‘id’ => ‘my_sidebar’, ‘description’ => ‘This is the widgetized Side Bar.’, ‘before_widget’ => ‘<div id=”%1$s” class=”widget %2$s”>’, ‘after_widget’ => ‘</div>’, ‘before_title’ => ‘<h4>’, ‘after_title’ => ‘</h4>’ )); } } //this will be … Read more

Custom Theme Bootstrap

If you have a LESS version of Bootstrap (non-compiled) you need to change the @grid-float-breakpoint variable to 992px to get the navbar to collapse on “Tablet” (Medium) breakpoint. Source: Changing the collapsed mobile navbar breakpoint The navbar collapses into its vertical mobile view when the viewport is narrower than @grid-float-breakpoint, and expands into its horizontal … Read more

Does WordPress theme customisation API support section hierarchy?

Yes, this is supported. They’re called panels, sections and controls. Adding a panel uses this code: $wp_customize->add_panel( $panel_name, array( ‘title’ => ‘panel_title’, ‘description’ => ‘panel_description’, ‘priority’ => ‘priority’, ‘capability’ => ‘edit_theme_options’, ‘theme_supports’ => ” )); Adding a section goes like this: $wp_customize->add_section($section_name , array( ‘panel’ => ‘panel_name’, ‘title’ => ‘section_title’, ‘description’ => ‘section_description’, ‘priority’ => … Read more

Displaying theme options in css

Although @Jevuska did solve my issue, I have found a much easier solution to adding dynamic CSS from my theme options page. Here we go! Add this to functions.php add_action(‘wp_head’, ‘my_custom_css’); function my_custom_css(){ require_once( get_template_directory() . ‘/css/theme-styles.php’ ); } Now you can treat theme-styles.php as a normal CSS stylesheet <style type=”text/css”> a { color: <?php … Read more