Excellent Programming Tricks


Sometime beginner programmers are depressed when they work with WordPress standard theme feature and custom theme features. When you want to customize any theme's core code you have to understand WordPress theme features activity.

Theme features
  1. Automatic feed links
    1. Functionality: Inside <head> adds RSS feed link.
    2. Code: add_theme_support( 'automatic-feed-links' );
    3. File: Mainly in functions.php.
    4. Add to theme: Mainly add_action( 'after_setup_theme', 'my_theme_function' );
  2. Custom Backgrounds
    1. Functionality: In dashboard can customize the background color and image. 
    2. Code: add_theme_support( 'custom-background' ); or add_theme_support( 'custom-background', apply_filters( 'wp_my_custom_background', array(
         'default-color' => 'f00',
         'default-image' => '',
        ) ) );
    3. File: Mainly in functions.php.
    4. Add to theme: Mainly add_action( 'after_setup_theme', 'my_theme_function' ); 
  3.  Custom Headers
    1. Functionality: In dashboard can customize/change the header image.
    2. Code: add_theme_support( 'custom-header', $defaults );
      $defaults = array(
       'default-image'          => '',
       'width'                  => 0,
       'height'                 => 0,
       'flex-height'            => false,
       'flex-width'             => false,
       'uploads'                => true,
       'random-default'         => false,
       'header-text'            => true,
       'default-text-color'     => 'ffffff',
       'wp-head-callback'       => '',
       'admin-head-callback'    => '',
       'admin-preview-callback' => '',
      );
    3. File: Mainly in functions.php.
    4. Add to theme: Mainly add_action( 'after_setup_theme', 'my_theme_function' ); 
    5. Support:
      1. $text-color = get_theme_support( 'custom-header', 'default-text-color' );
      2. if (get_header_image() ) {background-image: url(<?php echo esc_url( get_header_image() ); ?>);}
      3. $header_text_color = get_header_textcolor(); //text color: #ffffff;
  4. Post Thumbnails
    1. Functionality: In dashboard can add/remove the featured image for Posts, Pages or Custom Post Types.
    2. Code:add_theme_support( 'post-thumbnails' );
    3. File: Mainly in functions.php.
    4. Add to theme: Mainly add_action( 'after_setup_theme', 'my_theme_function' ); 
  5. Post Formats
    1. Functionality: Standardized list of meta information formats for Posts, Pages or Custom Post Types.
    2. Code:add_theme_support('post-formats', array('aside',  'image',  'video',  'quote',  'link',  'gallery',  'audio',) );
      1. $format = get_post_format( $post_id );
      2. set_post_format($post->ID, 'gallery' );
      3. if ( has_post_format('gallery') ) { ... } -- Basically within loop
    3. File: Mainly in functions.php.
    4. Add to theme: Mainly add_action( 'after_setup_theme', 'my_theme_function' ); 
  6. Title Tag
    1. Functionality: Inside <head> adds document title tag.
    2. Code: add_theme_support( 'title-tag' );
    3. File: Mainly in functions.php.
    4. Add to theme: Mainly add_action( 'after_setup_theme', 'my_theme_function' ); 
  7. Editor Style
    1. Functionality: Within the post edit screen link a custom stylesheet file to the TinyMCE editor.
    2. Code: add_editor_style( 'css/custom-editor-style.css' );
    3. File: Mainly in functions.php.
    4. Add to theme: Mainly add_action( 'after_setup_theme', 'my_theme_function' ); 
  8. Theme Markup
    1. Functionality: Apply HTML5 markup for explicitly on search forms, comment forms, comment lists, gallery and caption. 
    2. Code: add_theme_support( 'html5', array( 'gallery' ) );
    3. File: Mainly in functions.php.
    4. Add to theme: Mainly add_action( 'after_setup_theme', 'my_theme_function' ); 
  9. Theme Logo
    1. Functionality: Allow themes to add custom logo. 
    2. Code:
      add_theme_support( 'custom-logo', array(
       'height'      => 100,
       'width'       => 400,
       'flex-height' => true,
       'flex-width'  => true,
       'header-text' => array( 'site-title', 'site-description' ),
      ) );
    3. File: Mainly in functions.php.
    4. Url of custom logo: $custom_logo_id = get_theme_mod( 'custom_logo' );
      $image = wp_get_attachment_image_src( $custom_logo_id , 'full' );
      echo $image[0];
    5. Add to theme: Mainly add_action( 'after_setup_theme', 'my_theme_function' ); 
  10. Sidebars
    1. Functionality: Theme provide a specific type of column like sidebar. In dashboard sidebar contains in widget.
    2. Code: register_sidebar( $args );
      1. $args = array(
         'name'          => sprintf( __( 'Sidebar %d' ), $i ),
         'id'            => "sidebar-$i",
         'description'   => '',
         'class'         => '',
         'before_widget' => '<li id="%1$s" class="widget %2$s">',
         'after_widget'  => "</li>\n",
         'before_title'  => '<h2 class="widgettitle">',
         'after_title'   => "</h2>\n",
        );
    3. Register sidebar
      1. <?php if ( is_active_sidebar( 'sidebar-1' ) ) : ?>
         <ul id="sidebar-1">
          <?php dynamic_sidebar( 'sidebar-1' ); ?>
         </ul>
        <?php endif; ?> 
    4. Check sidebar contains a widget
      1.  <?php is_dynamic_sidebar(); ?> 
      2. True when sidebar contains a widget.
      3. Parameter not required.
    5. File: Mainly in functions.php.
    6. Add to theme: Mainly add_action( 'after_setup_theme', 'my_theme_function' ); 
  11. Content Width
    1. Functionality: Set the maximum allowed width for any content in the theme .
    2. Code:
      if ( ! isset( $content_width ) ) {
       $content_width = 600;
      }
    3. Recommended(css)
      .size-auto, 
      .size-full,
      .size-large,
      .size-medium,
      .size-thumbnail {
       max-width: 100%;
       height: auto;
      }
    4. File: Mainly in functions.php.
    5. Add to theme: Mainly add_action( 'after_setup_theme', 'my_theme_function' );
  12. Navigation Menus
    1. Functionality: Theme contains customized navigation menus. 
    2. Code:
      function my_menus() {
        register_nav_menus/register_nav_menu(
          array(
            'header-menu' => __( 'Header Menu' ),
            'footer-menu' => __( 'Footer Menu' )
          )
        );
      }
    3. File: Mainly in functions.php.
    4. Add to theme:
      1. add_action( 'after_setup_theme', 'my_menus' );  
      2. add_action( 'init', 'my_menus' );
Ref: https://codex.wordpress.org/Theme_Features

    No comments:

    Post a Comment


    Authentic аnd Excellent

    Website

    HTML Template

    Wordpress Theme

    Database applications

    OR

    Application services?

    Excellent Programming Tricks (EPT) || Iftekhar-IT || We develops the Web applications and the WordPress templates. || Excellent Programming Tricks (EPT)

    © 2020 Blogger Theme by Iftekhar IT || Excellent Programming Tricks

    Execllent Programming Tricks. Powered by Blogger.