Skip to content
This repository has been archived by the owner on Oct 10, 2018. It is now read-only.

Adds dynamic header and footer in WordPress theme. #36

Merged
merged 25 commits into from
Jan 23, 2018
Merged

Conversation

kopepasah
Copy link
Contributor

@kopepasah kopepasah commented Jan 19, 2018

Integrates dynamic header and footer from static templates.

Covers #33

@kopepasah kopepasah changed the title WIP - Add/33 WIP - Adds dynamic header and footer in WordPress theme. Jan 21, 2018
@kopepasah kopepasah requested a review from ThierryA January 21, 2018 23:47
@kopepasah kopepasah changed the title WIP - Adds dynamic header and footer in WordPress theme. Adds dynamic header and footer in WordPress theme. Jan 21, 2018
Copy link
Contributor

@ThierryA ThierryA left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work @kopepasah. I left my CR below.

}

$form = '<li class="menu-item menu-item-search-form">
<form role="search" method="get" target="_top" action="' . esc_url( home_url( '/' ) ) . '">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use get_search_form(). Let me know if it doesn't validate.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ThierryA the reason I did not use get_search_form() here is the default search for does not have the correct markup. We could create a search-form.php template with the markup required for this search form, but then that would apply to all other instances of get_search_form() as well.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kopepasah I think you should go ahead and use get_search_form(). The form sanitizer in ampproject/amp-wp#871 will automatically add target="_top" to the form here. Otherwise, we could still use get_search_form() and then use the get_search_form filter to inject the target attribute onto it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@westonruter the reason for this markup is not only to add the target attribute, it was for stylistic purposes. However, if it is required, I can rework it to use get_search_form().

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kopepasah if just for stylistic purposes then I think it would be good to create a search-form.php and then also use get_search_form(), like you suggested. We'd be making sure that the AMP plugin forces the default output of get_search_form() to be valid AMP, so it would be a good pattern to use for other themers to copy.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ended up creating a custom template and used get_search_form().

*
* @return string $items
*/
function ampconf_wp_nav_menu_items( $items, $args ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we perhaps have the search form after the nav ul. If it doesn't call to much styling changes, we can then add it to the header template.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ThierryA it definitely takes less styles to hook it into the header menu (not loads less, but less). Since we are not limited on HTML, but are limited on styles, I think this implementation is a little better for this use case.

Copy link
Contributor

@ThierryA ThierryA Jan 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kopepasah it actually doesn't require more styling 😄 (see the latest changes I pushed
). Is quite beneficial as we can call the search form straight in the header.php and avoid having the hook firing for all menus.

@@ -30,3 +30,31 @@ function ampconf_pingback_header() {
}
}
add_action( 'wp_head', 'ampconf_pingback_header' );

/**
* Adds the search for as the last top-level menu item.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe a word is missing here.

functions.php Outdated
return $amp_scripts;
}
add_filter( 'amp_component_scripts', 'ampconf_amp_component_scripts' );

/**
* Enqueue scripts and styles.
*/
function ampconf_scripts() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can get rid of this function since assets are dequeued by the AMP plugin. (We will add the necessary fallback for .org when we get to that story)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually not accurate. Assets don't get dequeued, but rather the printing is prevented. And with ampproject/amp-wp#887 actually the enqueued assets are used for printing.

functions.php Outdated
@@ -129,12 +132,40 @@ function ampconf_widgets_init() {
}
add_action( 'widgets_init', 'ampconf_widgets_init' );

/**
* Filters the AMP custom css to include the CSS from out theme.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo mistake.

functions.php Outdated
* @return array
*/
function ampconf_amp_component_scripts( $amp_scripts ) {
$amp_scripts['amp-form'] = 'https://cdn.ampproject.org/v0/amp-form-0.1.js';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be automatically be included by the plugin once the document sanitization is completed. Since it isn't the case at the moment, add // @todo as a reminder to remove it.

footer.php Outdated
</div><!-- .site-info -->
</footer><!-- #colophon -->
</div><!-- #page -->
<p class="wrap__item wrap__item--footer-copyright">&copy; <?php echo esc_html( date( 'Y' ) ); ?> <a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a></p>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think &copy; is universal but I think we should change it to <?php printf( '&copy; %s', esc_html( date( 'Y' ) ) ); ?> just to be safe.

functions.php Outdated
@@ -44,10 +44,13 @@ function ampconf_setup() {
*/
add_theme_support( 'post-thumbnails' );

// This theme uses wp_nav_menu() in one location.
/***
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trivial but /** is reserved for phpdoc, like for functions, methods, variable definitions, etc. For other cases, just use:

/*
...
*/

But since this is a single-line comment anyway, then // I think is right.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment changed.

functions.php Outdated

return $styles . $css;
}
add_filter( 'amp_custom_styles', 'ampconf_custom_styles' );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be eliminated in favor of regular enqueueing with ampproject/amp-wp#887

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Styles are now enqueued the standard method.

@kopepasah
Copy link
Contributor Author

@ThierryA adjusted based on your review and should be ready to go.

@ThierryA ThierryA requested a review from delawski January 23, 2018 11:18
@ThierryA ThierryA merged commit 33e83b2 into develop Jan 23, 2018
@ThierryA ThierryA deleted the add/33 branch January 23, 2018 11:20
@ThierryA ThierryA restored the add/33 branch January 23, 2018 11:26
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants