Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

Editing Function genesis_do_post_title

Hi,

I have set up my own site on wordpress and am using the genesis framework. And I now what to add a conditional to a hook that is already being used. Now I have been looking for days and perhaps I'm not getting it or asking the right question. Because alot of links explain how you call the hook which I get but I want to amend a hook being used so I want to find the original and make a change in my child theme.

But I'm not sure where the html that the hook calls lives hence my title where is the html? Am I trying to edit my site in the wrong??

3 Answers

A.J. Kandy
PLUS
A.J. Kandy
Courses Plus Student 12,422 Points

Without knowing the specifics of the hook you're trying to modify, most premium themes / frameworks have very modularized code - there's no single "html" file for a page template, but rather, a system of PHP partials.

Genesis stores most of its hooks in header.php, footer.php, and inside the /lib/framework.php files, as far as I know. I would start looking there. I think you can probably work backwards from the element you want to modify to find it. (Disclaimer: I am not a Genesis expert).

That said, modifying or overriding theme core function libraries can be a bit dangerous - keep a backup of any files you edit, in case you end up with a White Screen of Death.

Hopefully people will see this so I finally get the framework and I've removed the original function and added my own function in the child theme. Now what is probably the easy bit for people to help with.

So I'm editing the function genesis_do_post_title, and what I want to do is add a conditional like is_category() because I want wrap the post_title in an anchor tag if the post category is "work" in my case. Long story short below is the original function. Where do people think I should add my conditional.

$title = apply_filters( 'genesis_post_title_text', get_the_title() );

    if ( 0 === mb_strlen( $title ) )
        return;

    //* Link it, if necessary
    if ( ! is_singular() && apply_filters( 'genesis_link_post_title', true ) )
        $title = sprintf( '<a href="%s" rel="bookmark">%s</a>', get_permalink(), $title );

    //* Wrap in H1 on singular pages
    $wrap = is_singular() ? 'h1' : 'h2';

    //* Also, if HTML5 with semantic headings, wrap in H1
    $wrap = genesis_html5() && genesis_get_seo_option( 'semantic_headings' ) ? 'h1' : $wrap;

    //* Build the output
    $output = genesis_markup( array(
        'html5'   => "<{$wrap} %s>",
        'xhtml'   => sprintf( '<%s class="entry-title">%s</%s>', $wrap, $title, $wrap ),
        'context' => 'entry-title',
        'echo'    => false,
    ) );

    $output .= genesis_html5() ? "{$title}</{$wrap}>" : '';

    echo apply_filters( 'genesis_post_title_output', "$output \n" );

Also can anyone tell me why i can't get the code above to highlight in php language. Kinda of annoying I add php after the first three brackets but it doesn't like.