-
Notifications
You must be signed in to change notification settings - Fork 13
Adds dynamic header and footer in WordPress theme. #36
Changes from 10 commits
1c771d5
f5302b0
7b9d415
6f30f4c
f83df11
bf86b63
a9f3f03
b219f8d
61b15ec
a0ddd2c
efaf106
f50c801
66c2405
0416daf
f56cac2
d3bdd34
3f6f1cd
82de045
b83a900
2458e1f
efd1f6f
bbcb3a5
327d88b
9e0045e
5dd214d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. Trivial but
But since this is a single-line comment anyway, then There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comment changed. |
||
* Registers multiple menus | ||
*/ | ||
register_nav_menus( | ||
array( | ||
'menu-1' => esc_html__( 'Primary', 'ampconf' ), | ||
'header' => esc_html__( 'Header', 'ampconf' ), | ||
'footer' => esc_html__( 'Footer', 'ampconf' ), | ||
) | ||
); | ||
|
||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. Typo mistake. |
||
* | ||
* @param string $css The combined custom css. | ||
* | ||
* @return string $css | ||
*/ | ||
function ampconf_custom_styles( $css ) { | ||
$path = get_template_directory() . '/assets/dist/css/main.css'; | ||
$styles = file_get_contents( $path ); // phpcs:ignore WordPress.WP.AlternativeFunctions -- Not a remote file. | ||
|
||
return $styles . $css; | ||
} | ||
add_filter( 'amp_custom_styles', 'ampconf_custom_styles' ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Styles are now enqueued the standard method. |
||
|
||
/** | ||
* Adds custom component scripts to the document. | ||
* | ||
* @param array $amp_scripts AMP Component scripts, mapping component names to component source URLs. | ||
* | ||
* @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 commentThe 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 |
||
$amp_scripts['amp-bind'] = 'https://cdn.ampproject.org/v0/amp-bind-0.1.js'; | ||
|
||
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 commentThe 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 commentThe 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. |
||
wp_enqueue_style( 'ampconf-style', get_stylesheet_uri() ); | ||
|
||
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) { | ||
wp_enqueue_script( 'comment-reply' ); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. I believe a word is missing here. |
||
* | ||
* @param string $items The HTML list content for the menu items. | ||
* @param stdClass $args An object containing wp_nav_menu() arguments. | ||
* | ||
* @return string $items | ||
*/ | ||
function ampconf_wp_nav_menu_items( $items, $args ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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 commentThe 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 |
||
if ( 'header' !== $args->theme_location ) { | ||
return $items; | ||
} | ||
|
||
$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 commentThe reason will be displayed to describe this comment to others. Learn more. Use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ThierryA the reason I did not use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @kopepasah I think you should go ahead and use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @westonruter the reason for this markup is not only to add the There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I ended up creating a custom template and used |
||
<label> | ||
<span class="screen-reader-text">' . _x( 'Search for:', 'label', 'ampconf' ) . '</span> | ||
<input type="search" placeholder="' . esc_attr_x( 'Search', 'placeholder', 'ampconf' ) . '" value="' . get_search_query() . '" name="s" /> | ||
</label> | ||
|
||
<button type="submit"></button> | ||
</form> | ||
</li>'; | ||
|
||
return $items . $form; | ||
} | ||
add_filter( 'wp_nav_menu_items', 'ampconf_wp_nav_menu_items', 10, 2 ); |
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.