-
-
Save rgadon107/affe969751c19d7bfbcaa47d904bf2d7 to your computer and use it in GitHub Desktop.
Since you are filtering now, on line 32 you need to return $attributes. Also, you can remove the 'else' because you're returning early.
-
Removed
array
data type within function parameter. Parameter data type is already defined within the filter. -
Changed function name to better represent what it does.
-
Filled out doc block for filter and callback.
-
Added
$attributes
toreturn
on line 32. -
Added $attributes['id'] element at line 38.
-
Lines 37 - 42, changed array variable to array key => value pairs.
Robert,
There are some structure and functional problems in your code. Let's walk through them.
The first function
The else
codeblock is not needed at all. The first line should only happen if this web page is the front page OR a single post.
function ystl_add_blog_title() {
if ( ! is_front_page() && ! is_singular( 'post' ) ) {
return;
}
?>
<a href="http://ystl.dev" id="ystl-blog-title" class="featured-content blog-title">Yoga St. Louis Blog</a><br />
<?php
}
The second function
-
Remove the
else
gatekeeper. It's unnecessary. Why? Think about it. IF this is a front page OR a post, then it returns. Theelse
happens anyway if it's not the front page OR a post. Therefore, it's redundant and not needed. -
The event is :
genesis_attr_content-sidebar-wrap
. -
The code will not work until you take those attributes and then apply them yourself to the appropriate markup. Running your code, you get the following markup:
<div open="<div><a %>" class="featured-content" href="="http://sandbox.dev"" title="Yoga St. Louis Blog" close="</a>"><main class="content" id="genesis-content">
That's not what you want.
Rethinking it
I assume that you are trying to insert a blog title into the page. Correct? Then you want to do this instead:
add_action('genesis_after_content_sidebar_wrap', 'render_blog_page_title_after_content_sidebar_wrap' );
/**
* Render the blog page title after the `content-sidebar-wrap` HTML element.
*
* @since 1.0.0
*
* @return void
*/
function render_blog_page_title_after_content_sidebar_wrap() {
if ( ! is_front_page() && ! is_singular( 'post' ) ) {
return;
}
// move the HTML to a view file to keep the concerns separate.
?>
<h2><a href="http://ystl.dev" id="ystl-blog-title" class="featured-content blog-title">Yoga St. Louis Blog</a></h2>
<?php
}
// Final result:
add_action('genesis_before_content', 'render_blog_page_title_after_content_sidebar_wrap' );
/**
-
Render the blog page title on the front and post pages.
-
@SInCE 1.0.0
-
@return void
*/
function render_blog_page_title_after_content_sidebar_wrap() {if ( is_front_page() || is_singular( 'post' ) ) {
include( __DIR__ . '/lib/structure/views/blog-title.php' );
}
}
//Code included from view file (commented out for demonstration purposes):
Yoga St. Louis Blog
// Note: the php echo
command in the view file was necessary to render the site url to the browser. The WP callback by itself
// returns an empty string.
Is the code block below line 23 a better way to go?