Quantcast
Channel: Yudiz Solutions Ltd.
Viewing all articles
Browse latest Browse all 595

Customization in WordPress

$
0
0

Currently, WordPress is the widely used Content Management System in the world and is being utilized by nearly 75 million websites. Here I am trying to bring in front of you few primary customization required while you are developing your website in WordPress.

How to make custom widget area?

To make custom widget area, you need to write following code in your functions.php file which could be either in parent/child theme.

Code for functions.php:

register_sidebar(array(
        'id' => 'widget-id',     
        'name' => 'widget name',
        'description' => 'description',
        'before_widget' => '<div id="%1$s" class="widget %2$s">',
        'after_widget' => '</div>',
        'before_title' => '<h4 class="widgettitle">',
        'after_title' => '</h4>',
));

Code to be written in php file where you want to display the content of the created widget:

<?php dynamic_sidebar('widget-id'); ?>

Screenshot-1

Screenshot-1.1

How to allow php code in widget?

To allow php code in widget you need to add following code into your function file i.e functions.php

Code:

function execute_php($html){
     if(strpos($html,"<"."?php")!==false){ ob_start(); eval("?".">".$html);
          $html=ob_get_contents();
          ob_end_clean();
     }
     return $html;
}
add_filter('widget_text','execute_php',100);

Screenshot-2

Screenshot-2.1

How to enable shortcode in widget?

To enable shortcode in widget you need to write below code in your functions.php file.

Code:

add_filter('widget_text', 'do_shortcode');

Screenshot-3

Screenshot-3.1

How to create custom menu?

To create custom menu in wordpress follow the below steps.

You need to write the below code in function file:

function my_custom_menus() {
    register_nav_menus(
            array(
                    'footer-menu' => __( 'Footer Menu' )
            )
    );
}
add_action( 'init', 'my_custom_menus' );

Write the below code in php file where you want to display the custom menu.

Screenshot-3

Screenshot-3.1

How to limit the length of the excerpt and change the by default read more excerpt string i.e […]?

You need to write the following code into your function file.

Code to limit the length of excerpt is as below:

function custom_excerpt_length( $length ) {
    return 30;
}
add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );

Code to change the read more excerpt string is as below:

function wpdocs_excerpt_more( $more ) {
    return '...';
}
add_filter( 'excerpt_more', 'wpdocs_excerpt_more' );

Screenshot-3

Screenshot-3.1

How to include your parent theme’s stylesheet into child theme?

There are two ways we can include to do this:

  1. You need to write below code into your child theme’s stylesheet.
    @import url("../your-theme-name/style.css");
  2. You need to write the below mention code into your function file of the child theme.
    add_action( 'wp_enqueue_scripts', 'enqueue_parent_styles' );
          function enqueue_parent_styles() {
          wp_enqueue_style( 'parent-style',   get_template_directory_uri().'/style.css');
    }

Second method is more preferable than first method as in first one all the css that are included will be downloaded consecutively which will reduce the page speed.

How to create custom templates for pages, header and footer?

Custom Page Template:

To create a template for a particular page, first select the suitable template then make a copy of it and place it in child theme. Here I am trying to make a template file for landing page.

Custom Header:

To create custom header for any page you need to make a copy of header.php and rename it like header-landing.php (you can add any word after header-).Here I am creating header for landing page so I will name it header-landing.php

Custom Footer:

To create custom footer for any page you need to make a copy of footer.php and rename it like footer-landing.php (you can add any word after footer-).Here I am creating footer for landing page so I will name it footer-landing.php

Screenshot-8

Screenshot-8.1

Screenshot-8.2


Viewing all articles
Browse latest Browse all 595

Trending Articles