Using Templates in WordPress

Using Templates in WordPress

Posted on

In themes: get_template_part( ‘slug-name’, ‘name’ );We should keep our templates inside template-parts directory.So lets say our template file is in: themes/theme-name/template-parts/home/home-my-template.phpTo include this template you will write ( for e.g. inside front-page.php ) For e.g. our template file is in: themes/theme-name/template-parts/home/my-template.php In Plugin, For e.g. our template file is in:plugins/plugin-name/templates/my-template.php If we want to pass

Read More

Using Underscore JS _.template() in WordPress

Using Underscore JS _.template() in WordPress

Posted on

Many times we come across a situation in JavaScript where we have to generate dynamic html You can see the code above looks messy and difficult to read. WordPress recommends to use underscore templates.WordPress already has support for underscore.js library. All you have you to do is enqueue it like so : Then you can create a template

Read More

Fix PHPCS errors in WordPress

Fix PHPCS errors in WordPress

Posted on

Visibility must be declared on method “__construct” Add public before the class method Detected usage of a non-sanitized input variable: $_POST[‘xyz’] You need to sanitize it. E.g. esc_html( $_POST[‘xyz’] ) or sanitize_text_field( $_POST[‘xyz’] )  Detected usage of a possibly undefined superglobal array index: $_POST[‘query’]. Use isset() or empty() to check Wrap it inside empty() e.g.

Read More