Skip to content

Instantly share code, notes, and snippets.

@mehedidb
Last active September 22, 2018 14:42
Show Gist options
  • Save mehedidb/040c55ffbcc99dfc3b1e907a028e8d31 to your computer and use it in GitHub Desktop.
Save mehedidb/040c55ffbcc99dfc3b1e907a028e8d31 to your computer and use it in GitHub Desktop.
WordPress Theme Development Problem Theme Development Requirment List.

WordPress Theme Development Requirment List

list created by Mehedi Hasan.

IMPORTANT LINKS

Approved Tips and Standard Handles

  1. Don't use inline style, if need any style in inline you must have used to <?php wp_add_inline_style( $handle, $data ); ?> function to use add inline style. you can see the proper uses mathod to add inline style inline style codex link.

  2. Don't use inline script, if need any script in inline you must have used to <?php wp_add_inline_script( string $handle, string $data, string $position = 'after' ); ?> function to use add inline script. you can see the proper uses mathod to add inline script inline script codex link.

  3. Use <?php get_search_form(); ?> filter for searchform customization in searchform.php Search Form Codex Link. example:

<?php
  add_filter('get_search_form', function($form) {
      $form = '<form action="'.esc_url(home_url('/')).'">
                  <input name="s" id="search" placeholder="'.esc_attr__('Search...', 'dawat').'" type="search">
                  <button type="submit"><i class="fa fa-search"></i></button>
               </form>';
      return $form;
  });
  1. Don't do any hard codeing.

  2. Use echo function insted of print function.

  3. Scrapeing all translatable string.

  4. Don't do scrapeing to WordPress default function.

  5. Require File Including By require_once(); or require(); and avoid to use include(); or include_once();.

  6. Use add_editor_style( array|string $stylesheet = 'editor-style.css' ) Function For Editor style and select the foder file (Example Theme 2017)

  7. Use wp_add_inline_script( string $handle, string $data, string $position = 'after' ) Function For Editor Inline Script.

  8. Use Re/Write Rules wp_rewrite_rules() Function For Link Update. (Example On Comet)

  9. Suppports widgets in widget_text().example...

add_filter( 'widget_text', 'shortcode_unautop');
add_filter( 'widget_text', 'do_shortcode');
  1. Add Custom Link in when go user the blog page..ust copy the code and paste it in after_setup_theme() hook. example...
  /**
   * Detect Homepage
   *
   * @return boolean value
   */
  if( !function_exists('appro_detect_homepage') ){
      function appro_detect_homepage() {
          /*If front page is set to display a static page, get the URL of the posts page.*/
          $homepage_id = get_option( 'page_on_front' );

          /*current page id*/
          $current_page_id = ( is_page( get_the_ID() ) ) ? get_the_ID() : '';

          if( $homepage_id == $current_page_id ) {
              return true;
          } else {
              return false;
          }
      }
  }

Then need to EXTEND Nav_Walker Class..and require() the file in function php. example...

class appro_Nav_Menu_Walker extends Walker_Nav_Menu {
	function start_el(&$output, $item, $depth = 0, $args = array(), $id = 0) {
		global $wp_query;
		$indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';

		$class_names = $value = '';

		$classes = empty( $item->classes ) ? array() : (array) $item->classes;

		$class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) );
		$class_names = ' class="' . esc_attr( $class_names ) . '"';

		$output .= $indent . '<li id="menu-item-'. $item->ID . '"' . $value . $class_names .'>';

		$attributes = ! empty( $item->attr_title ) ? ' title="' . esc_attr( $item->attr_title ) .'"' : '';
		$attributes .= ! empty( $item->target ) ? ' target="' . esc_attr( $item->target ) .'"' : '';
		$attributes .= ! empty( $item->xfn ) ? ' rel="' . esc_attr( $item->xfn ) .'"' : '';

		if( appro_detect_homepage() == true ) {
				$attributes .= ! empty( $item->url ) ? ' href="' . esc_attr( $item->url ) .'"' : '';
		} else {
				if( $item->type_label == 'Custom Link' ) {
						$attributes .= ! empty( $item->url ) ? ' href="' . get_site_url() .  esc_attr( $item->url ) .'"' : '';
					} else {
						$attributes .= ! empty( $item->url ) ? ' href="' . esc_attr( $item->url ) .'"' : '';
				}

		}


		$item_output = $args->before;
		$item_output .= '<a'. $attributes .'>';
		$item_output .= $args->link_before . do_shortcode(  apply_filters( 'the_title', $item->title, $item->ID )) . $args->link_after;
		$item_output .= '<span class="sub">' . do_shortcode( $item->description ) . '</span>';
		$item_output .= '</a>';
		$item_output .= $args->after;

		$output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
	}
}

Now need to call the walker class in wp_nav_menu(). example...

	if(has_nav_menu('mainmenu')) {
	    wp_nav_menu(array(
		'theme_location' => 'mainmenu',
		'container' => 'div',
		'container_class' => 'stellarnav bs-example-js-navbar-scrollspy',
		'container_id' => 'main-nav',
		'menu_class' => 'nav navbar-nav',
		'menu_id' => 'nav',
		'fallback_cb' => 'dawat_mainmenu_default_fallback',
		'walker'    => new appro_Nav_Menu_Walker(),
	    ));
	}
  1. Add Favicon.
/* Add Favicon
----------------------------------*/
if (!function_exists('add_favicon')) {
    function add_favicon() {
        
    // Favicon Icon
    if (cs_get_option( 'favicon_icon' )) {
        $favicon_icon = cs_get_option( 'favicon_icon' );
    }else{
        $favicon_icon = get_template_directory_uri().'/assest/img/favicon.png';
    }
        echo '<link rel="shortcut icon" type="image/png" href="'.$favicon_icon.'" />';
    }
} 
add_action('wp_head', 'add_favicon');
  1. Menu Default Falback
/* Set Main Menu
----------------------------------*/
if (!function_exists('dawat_mainmenu_default_fallback')) {
    function dawat_mainmenu_default_fallback() {
        ?>

        <ul id="nav" class="nav navbar-nav">
            <li><a href="<?php echo admin_url(); ?>nav-menus.php"><?php _e( 'Set Mainmenu Here...', 'dawat' ); ?></a></li>
        </ul>   

        <?php
    }
}
  1. Custom Excerpt Lenth and Button.
/*
Excerpt Custom Lenth And More Button.
---------------------------------------*/

function dawat_excerpt_custom_lenth($value){
	return 30;
}
add_filter( 'excerpt_length', 'dawat_excerpt_custom_lenth' );

function dawat_excerpt_custom_more($value){
	$read_more = '<a href="'.get_the_permalink().'"> [ Read More ]</a>';
	return $read_more;
}
add_filter( 'excerpt_more', 'dawat_excerpt_custom_more' );
/*
	Custom font icon implement in king composer.
	Return: King Composer new icon set.		
---------------------------------------------*/
function dawat_composer_custom_icon_implement() {
 
	if( function_exists( 'kc_add_icon' ) ) { 
		kc_add_icon( get_template_directory_uri().'/assest/css/bicon.min.css' ); 
	}
 
}
add_action('init', 'dawat_composer_custom_icon_implement');
/*
	Contact Form 7 Extra Class add.
	Return: A New Class In Contact Form 7.		
-----------------------------------------*/
function dawat_custom_form_class_attr( $class ) {
  $class .= ' table-booking-form';
  return $class;
}
add_filter( 'wpcf7_form_class_attr', 'dawat_custom_form_class_attr' );
  1. Including Google Fonts.
/*-- Google-Fonts-Function --*/
if( !function_exists('prefix_get_google_font_url') ){
    function prefix_get_google_font_url(){
        	$fonts_url = '';
            $fonts     = array();
            $subsets   = 'latin,latin-ext'; 
            /* translators: If there are characters in your language that are not supported by Merriweather, translate this to 'off'. Do not translate into your own language. */
            if ( 'off' !== _x( 'on', 'Poppins font: on or off', 'appro' ) ) {
                $fonts[] = 'Poppins:100,100i,200,200i,300,300i,400,400i,500,500i,600,600i,700,700i,800,800i,900,900i';
            }

            if ( $fonts ) {
                $fonts_url = add_query_arg( array(
                    'family' => urlencode( implode( '|', $fonts ) ),
                    'subset' => urlencode( $subsets ),
                ), 'https://fonts.googleapis.com/css' );
            }

            return esc_url_raw( $fonts_url );
    }    
}

OR

//Adding Google Fonts..
function prefix_get_google_fonts(){
	$fonts = array();
	$fonts[]='Montserrat:400,700';
	$fonts[]='Raleway:300,400,500';
	$fonts[]='Halant:300,400';

	$prefix_fonts = add_query_arg(array(
		'family' => implode('|', $fonts)
		),'https://fonts.googleapis.com/css');

	return $prefix_fonts;
}
  1. Keep Link In Excerpt Post. Refference
function keep_my_links($text) {
  global $post;
if ( '' == $text ) {
    $text = get_the_content('');
    $text = apply_filters('the_content', $text);
    $text = str_replace('\]\]\>', ']]&gt;', $text);
    $text = preg_replace('@<script[^>]*?>.*?</script>@si', '', $text);
    $text = strip_tags($text, '<a>');
  }
  return $text;
}
remove_filter('get_the_excerpt', 'wp_trim_excerpt');
add_filter('get_the_excerpt', 'keep_my_links');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment