How to remove search bar based on page template

Currently, the search bar is a widget in the primary sidebar.

I want to remove it from all pages except those using a specific page template (let’s call that template “searchable.php”).

My most recent attempt, which sits in an mu-plugins file:

function nwb_remove_search_widget() {
    global $post;
    if ( get_page_template_slug( $post->ID ) == 'searchable.php' ) return;
add_action( 'widgets_init', 'nwb_remove_search_widget' );

This doesn’t work. I think the problem may be that the page template hasn’t been established at ‘widgets_init’, so the condition test returns false.

I have also tried ‘is_page_template(‘searchable.php’) to no avail.

I have also tried this…

add_action( 'the_post', 'nwb_remove_search_widget' );

…to no avail.

Thanks in advance for any help anyone might send my way.

How to get template drop down menu in page-attributes of custom post type?

When I register my custom post type, I set this:

'hierarchical'   => true,
'supports'       => array( 'title','author', 'page-attributes' ),

So, I am supose to see ‘order’, ‘templates’, ‘parents’ in Attributes box when create new post. But, I don’t see the ‘templates’ drop down showing up.
Anything else I should do to enable the choice of ‘templates’ ?

Conga template issue

Can we use OR & IF Statement in Word Template?

I am aware about the IF Statement in conga template but my issue is there are two field:

  1. Cash Advance
  2. Marketing Advance

[CASH ADVANCE] have some content
[MARKETING ADVANCE] have some content

Now i want to use OR statement like :


Can anyone help to add OR statement with above ?

WooCommerce – Load Templates From Plugin For All Template Files

I’ve read a bunch of articles about overriding the default /woocommerce/ templates and tried implementing the following (which were the best/most relevant that I could find all to no avail):

  • Load WooCommerce templates from my plugin folder first
  • Override WooCommerce Template File Within a Plugin

Essentially, what I would like to accomplish is: load all template files (for archives and posts not just template parts) from ~/wp-content/my-plugin/templates/woocommerce/* UNLESS the files are in my theme (and I don’t have to override each file instance in my function) . For instance:

  • ~/wp-content/my-plugin/templates/woocommerce/single-product.php (this seems like it just doesn’t want to load via plugin)
  • ~/wp-content/my-plugin/templates/woocommerce/archive-products.php (this seems like it just doesn’t want to load via plugin)
  • ~/wp-content/my-plugin/templates/woocommerce-pdf-invoices-packing-slips/* (I also want to be able to override other plugin extension templates just like I would be able to in my child theme)


The friendly folks at SkyVerge sent me the following code, which I tested and confirm that it works for template parts.

// Locate the template in a plugin
function myplugin_woocommerce_locate_template( $template, $template_name, $template_path ) {

    $_template = $template;

    if ( ! $template_path ) {
        $template_path = WC()->template_path();

    $plugin_path = myplugin_plugin_path() . '/templates/';

    // Look within passed path within the theme - this is priority
    $template = locate_template(
            trailingslashit( $template_path ) . $template_name,

    // Modification: Get the template from this plugin, if it exists
    if ( ! $template && file_exists( $plugin_path . $template_name ) ) {
        $template = $plugin_path . $template_name;

    // Use default template
    if ( ! $template ) {
        $template = $_template;

    return $template;
add_filter( 'woocommerce_locate_template', 'myplugin_woocommerce_locate_template', 10, 3 );

// Helper to get the plugin's path on the server
function myplugin_plugin_path() {
    // gets the absolute path to this plugin directory
    return untrailingslashit( plugin_dir_path( __FILE__ ) );

The above code works for something like:

  • ~/myplugin/templates/single-product/product-image.php

But does NOT work for:

  • ~/myplugin/templates/single-product.php

Where I’m getting stuck:

  • There are solutions to override bits and pieces of WC templates, but there I’ve not found / been able to create a solution that does comprehensive overrides (i.e. overriding ability just like a child theme would)
  • I can’t seem to find the right combination of filter hooks; single-product.php and archive-product.php seem to be controlled by functions outside the standard WC template functions

Thanks in advance!

How to add HTML5 validation to Freeform Pro Composer Bootstrap template

This is the code for a Freeform Pro Bootstrap Composer template. How to add HTML5 validation for all the possible ‘required’ instances: textfield, textarea, radios, checkboxes, selects?

Normally, in static Freeform templates I would use Bootstrap js validation. But when it comes to flexibility and ease of use for clients to compose forms with required fields it is more easy to use HTML5 validation as there are no variables required in scripts. And last but not least, it is much easier to use HTML5 validation in a multi language site.

So, I hope someone can help me with this: how to add HTML5 validation to this Freeform Pro Composer Bootstrap template?

{composer:page} {composer:rows}
{if composer:field_total == 0} {/if} {composer:fields} {if composer:field_type == 'nonfield_title'}


{if:elseif composer:field_type == 'nonfield_paragraph'} {composer:field_output} {if:else}
{if composer:field_label} {if composer:field_type == 'nonfield_captcha'} {if freeform:captcha} {/if} {if:elseif composer:field_type == 'checkbox'} {!-- We'll display its label later down the page --} {if:else} {/if} {/if} {if composer:field_output} {if composer:field_type == 'nonfield_captcha'} {if freeform:captcha}
{/if} {if:elseif composer:field_type == 'checkbox_group'} {freeform:field:{composer:field_name} wrapper_open="" wrapper_close="" row_wrapper_open="
" label_wrapper_open="" label_wrapper_close="" input_wrapper_open="" input_wrapper_close="" order="CL" attr:id="freeform_{composer:field_name}" } {if:elseif composer:field_type == 'checkbox'}
{if:elseif composer:field_type == 'radio'} {freeform:field:{composer:field_name} wrapper_open="" wrapper_close="" row_wrapper_open="
" label_wrapper_open="" label_wrapper_close="" input_wrapper_open="" input_wrapper_close="" order="RL" attr:id="freeform_{composer:field_name}" } {if:elseif composer:field_type == 'file_upload'} {composer:field_output} {if:elseif composer:field_type == 'nonfield_dynamic_recipients'} {composer:field_output} {if:elseif composer:field_type == 'nonfield_submit'} {if:elseif composer:field_type == 'nonfield_submit_previous'} {!-- for multi-page forms --} {if:else} {freeform:field:{composer:field_name} attr:id="freeform_{composer:field_name}" attr:class="form-control" attr:placeholder="{composer:field_label}" } {/if} {/if}
{/if} {/composer:fields}
{/composer:rows} {/composer:page}

Best practice provision form library with custom template

I exported a site collection template that I wanted to apply a brand new site collection. The problems start with the form libraries:


The proces stops here with this:

Apply-PnPProvisioningTemplate : Invalid template URL. The template
must exist in the Forms directory of this document library. Create the
template in the Forms directory, and then re-type the Web address.
Note that you cannot move or copy a template into the Forms directory.

This is strange, because the template indeed says:

The form library has a template created with InfoPath. The problem might be that the template itself is not downloaded, at least I don’t see neither any trace in the template xml nor a file created in the target folder. I used the following command to create the pnp template:

Get-PnPProvisioningTemplate -Out "C:UsersmeDocumentsPnPtemplateclone.xml" -Schema LATEST -PersistBrandingFiles -PersistPublishingFiles -Handlers All -IncludeNativePublishingFiles

I searched for the issue, but all I found was a bug on github related to content types and I don’t use a custom content type.

So, the question is, how can I create the form library with PnP? Any advise appreciated.

How do I render form fields in my custom.tpl.php template?

Here’s my dilemma, I built a custom form-based module that allows a user to vote on a future conference location but I’m having a issue printing or rendering my form fields to have them display in my custom block template.


      'title' => t('Administer event voting form'),
      'description' => t('Allows users to implement custom css class for the Event Voting Form module'),

 * Implements hook_block_info().
function eventvoting_block_info() {
  $block['eventvoting_block'] = array(
    'info' => t('Event Voting Form Block'),
    'cache' => DRUPAL_CACHE_PER_ROLE,
  return $block;

 * Implementation of hook_block_view()
function eventvoting_block_view($delta = '') {
  $block = array();

  switch ($delta) {
    case 'eventvoting':
      $block['subject'] = t('');
      $block['content'] = array(
        '#theme' => 'eventvoting',
        '#vote_event_name' => variable_get('event_name'),
        '#vote_city' => variable_get('city'),
        '#vote_name' => variable_get('name'),
        '#vote_email' => variable_get('email'),
        '#vote_submit' => variable_get('submit'),
  return $block;

 * Implements hook_theme
function eventvoting_theme(){
  return array (
    'eventvoting' => array (
      'arguments' => array(
        'vote_event_name' => NULL,
        'vote_city' => NULL,
        'vote_name' => NULL,
        'vote_email' => NULL,
        'vote_submit' => NULL,
      // Use a template file called eventtheme.tpl.php
      'template' => 'theme/eventtheme',

 * Implements hook_menu().
function eventvoting_menu() {
  $items['event-voting-form'] = array(
    'title' => 'Event Voting Form',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('eventvoting_form'),
    // Use the default/standard site configuration permission.
    'access arguments' => array('administer site configuration'),
    'type' => MENU_NORMAL_ITEM,
  return $items;    

 * Creates/returns a form to configure the block's variables.
 * @param array $form
 * @param array $form_state
 * @return array
function eventvoting_form($form, &$form_state) {

  $form['event_name'] = array(
        '#title' => t('Select an event:'),
        '#type' => 'textfield',
        '#default_value' => variable_get('event_name'),
        '#required' => TRUE,
        '#weight' => 0,

    $form['city'] = array(
        '#title' => t('Vote for a city:'),
        '#type' => 'textfield',
        '#default_value' => variable_get('city'),
        '#required' => TRUE,
        '#weight' => 0,

    $form['name'] = array(
        '#title' => t('Your name:'),
        '#type' => 'textfield',
        '#default_value' => variable_get('name'),
        '#required' => TRUE,
        '#weight' => 0,

    $form['email'] = array(
        '#title' => t('Your email:'),
        '#type' => 'textfield',
        '#default_value' => variable_get('email'),
        '#required' => TRUE,
        '#weight' => 0,

    $form['save'] = array(
        '#type' => 'submit',
        '#value' => t('Vote'),

    return $form;


eventheme.tpl.php (inside the "theme" directory)


Vote for Next Year's Event

My goal is to render my fields of choice. The theme renders in the block but not the fields,

This has been racking my brain for a few hours now, any help and assistance would be GREATLY appreciated.

issues with Custom Post Type retaining page template value after publishing

As the title of this post implies, I am having issues creating/editing posts of a Custom Post Type, assigning it a page template via the ‘Attributes’ metabox and having that page template display as the selected option of the ‘Templates’ menu to always display the currently
selected template as the default option so that re-publishing the
page without re-selecting the current template does not cause it to
switch to the default template?

  • Regardless of the answer to #1, can I assign a default template for a Custom Post Type so that even on its initial creation, the most-used template (as defied by the developer) will be the default?
  • Here is what I have in my child theme’s functions.php to add the metabox and supposedly set its value as the default/selected value on subsequent edits.

    /** Custom Post Type Template Selector **/
    function cpt_add_meta_boxes() {
        $post_types = get_post_types();
        foreach( $post_types as $ptype ) {
            if ( $ptype !== 'page') {
                add_meta_box( 'cpt-selector', 'Attributes', 'cpt_meta_box', $ptype, 'side', 'core' );
    add_action( 'add_meta_boxes', 'cpt_add_meta_boxes' );
    function cpt_remove_meta_boxes() {
        $post_types = get_post_types();
        foreach( $post_types as $ptype ) {
            if ( $ptype !== 'page') {
                remove_meta_box( 'pageparentdiv', $ptype, 'normal' );
    add_action( 'admin_menu' , 'cpt_remove_meta_boxes' );
    function cpt_meta_box( $post ) {
        $post_meta = get_post_meta( $post->ID );
        $templates = wp_get_theme()->get_page_templates();
        $post_type_object = get_post_type_object($post->post_type);
        if ( $post_type_object->hierarchical ) {
            $dropdown_args = array(
                'post_type'        => $post->post_type,
                'exclude_tree'     => $post->ID,
                'selected'         => $post->post_parent,
                'name'             => 'parent_id',
                'show_option_none' => __('(no parent)'),
                'sort_column'      => 'menu_order, post_title',
                'echo'             => 0,
            $dropdown_args = apply_filters( 'page_attributes_dropdown_pages_args', $dropdown_args, $post );
            $pages = wp_dropdown_pages( $dropdown_args );
            if ( $pages ) { 
                echo "


    "; echo ""; echo $pages; } } // Template Selector echo "


    "; echo ""; // Page order echo "


    "; echo "

    menu_order) . "" />

    "; } function save_cpt_template_meta_data( $post_id ) { if ( isset( $_REQUEST['_wp_page_template'] ) ) { update_post_meta( $post_id, '_wp_page_template', $_REQUEST['_wp_page_template'] ); } } add_action( 'save_post' , 'save_cpt_template_meta_data' ); function custom_single_template($template) { global $post; $post_meta = ( $post ) ? get_post_meta( $post->ID ) : null; if ( isset($post_meta['_wp_page_template'][0]) && ( $post_meta['_wp_page_template'][0] != 'default' ) ) { $template = get_stylesheet_directory() . '/' . $post_meta['_wp_page_template'][0]; } return $template; } add_filter( 'single_template', 'custom_single_template' ); /** END Custom Post Type Template Selector **/

    Any ideas where I’m going wrong?