-
Notifications
You must be signed in to change notification settings - Fork 13
Adds dynamic header and footer in WordPress theme. #36
Conversation
There was a problem hiding this 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.
inc/template-functions.php
Outdated
} | ||
|
||
$form = '<li class="menu-item menu-item-search-form"> | ||
<form role="search" method="get" target="_top" action="' . esc_url( home_url( '/' ) ) . '"> |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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()
.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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()
.
inc/template-functions.php
Outdated
* | ||
* @return string $items | ||
*/ | ||
function ampconf_wp_nav_menu_items( $items, $args ) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
inc/template-functions.php
Outdated
@@ -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. |
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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'; |
There was a problem hiding this comment.
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">© <?php echo esc_html( date( 'Y' ) ); ?> <a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a></p> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think ©
is universal but I think we should change it to <?php printf( '© %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. | |||
/*** |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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' ); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
@ThierryA adjusted based on your review and should be ready to go. |
# Conflicts: # assets/dist/css/main.css
Dependent on ampproject/amp-wp#887 before working.
Integrates dynamic header and footer from static templates.
Covers #33