Add a custom action-hook in a child-theme?

  • Hendryk

    #5117

    Hey there 🙂

    I wondered if it is possible to “register” my own “custom action-hook” for widgets within a child theme? I would like to have an action-hook just in place where the graphene-adsense would go. Obviously it’s not as simple as just putting some code like

    <?php do_action( 'graphene_my_own_actionhook' ); ?>

    I guess I would have to define that first somewhere else in my child-theme’s functions.php for example?

    Thanks for your help –

    Graphene Theme rocks! 😉

    Mod

    Kenneth John Odle

    #30721

    An action hook acts like a shelf that you can put things on.

    In this case, there is already a shelf there: Graphene’s Google Adsense Options. You are not limited to adding Adsense code there; you can pretty much add whatever html or css you would like.

    Hendryk

    #30722

    Yes, I know there is that adsense option … but as it is filtered through some wordpress function I cannot add any code there I want, especially not any PHP-Code or (what I tried last) a PayPal-Donate button which actually uses basic HTML Form-Tags as <form> and <input type="hidden"> and an image that will pass the necessary parameters from the form-tags to PayPal. So, this is not quite true – as I already found out earlier in a different situation: https://forum.graphene-theme.com/graphene-support/adsense-options-possible-to-use-php-code-or-widget-shortcodes

    I tried to find a solution myself and tracked down in the theme files where this “filter” for the adsense-option was set. I think it’s the function wp_kses_post() which is called in the theme file located in admin/options-validator.php on line 203. I would not know how to change that or even how to override that in a function within my child-theme’s function.php (if possible at all?). Probably there was some reason to filter the adsense-code in that way – though I don’t yet understand it.

    Back to the hooks: the function that will “scan” for the action hooks is defined in the includes/theme-functions.php, line 76 and following. Though I don’t wanna touch any theme files like with the adsense option above. If it would be possible to add the child-theme directory to that function it might be possible to add action hooks myself in child-themes?

    Maybe I keep digging too much into the core theme files and don’t understand PHP and the theme code enough … ?

    ronangelo

    #30723

    Could you clarify your question. You would like to put “What” “Where” ?

    There are already a lot of action hooks that are available for almost every part of the theme.

    Hendryk

    #30724

    My initial question was actually pretty general: whether I can put an own action hook just anywhere in a child template. If it is a custom loop-single.php or a loop-custom-post-type.php does not matter – nor what code (html or php) will be put into the php-widget that I could place in that new action-hook widget area. I should be able to put php, html or javascripts there as I can do with any other action hook when I use a php-widget.

    The closest built-in graphene action hook to there where the “adsense code” (using the built-in adsense option) would go is the action hook called “graphene_before_comment_template” – though it is, if you look into the code of loop-single.php, not really close there and after the code inserted by the adsense-option. The closest hook just before that is called “graphene_post_footer” – which is, by the way, still in the main content’s div’s. So, there is, for example, no action hook before/after the post’s author info box (but after the main content div-tags) where I would need them.

    I am restyling a custom post type while all the rest of the project’s page use the graphene theme pretty unspectacular. One of the things I am going to try to realize is to display other posts (defined in custom fields of the custom post type’s post) like sub-pages are shown on pages in the graphene theme. If I want to achieve that through php-widgets and want to decide later where exactly (before/after author-info box and adsense-“box”) those things will appear, I would need one or two more action hooks that are not there currently. So that’s why I’m actually asking how I could register my own hooks in a graphene-child-theme.

    Anonymous

    #30726

    @Hendryk,

    I have a question not related to what you asked here…

    I was on your website and notice that you were able to delete http://www.hollbeck.net/blog/author/ which would lead to default wordpress author page. It gets redirected to http://www.hollbeck.net/autor/

    How did you do that? I always wanted to get rid of the default WordPress author page.

    Thank you.

    Mod

    Kenneth John Odle

    #30727

    Even if you add your own widget area, you will still need to use a PHP Widget to add PHP code to it.

    Hendryk

    #30728
    Quote:
    Even if you add your own widget area, you will still need to use a PHP Widget to add PHP code to it.

    Yes – that’s exactly what I want! 😉

    But how to insert my own widget area resp. action hook?

    ==

    OT @Sanuja:

    You mean the standard author page from wordpress that would lead to the trail /author/[mysuername]/ ?

    I did that making the following function inside my function.php (child-theme!):

    function hch_change_author_link( $link, $author_id, $author ) {
    if ( '[myusername]' == $author )
    return 'http://www.hollbeck.net/autor/?rel=author';
    return $link;
    }
    add_filter( 'author_link', 'hch_change_author_link', 10, 3 );

    rename the function as what you like and replace [myusername] with your wordpress-username. The “?rel=author” was added to my URL for google 😉

    I also found that somewhere in a forum… could not find the link to it now.

    Admin

    Syahir Hakim

    #30729

    What about just using the graphene_adsense hook? It’s in includes/theme-loop.php.

    Hendryk

    #30730

    oooops 😀

    I didn’t notice that one … was it added recently as a “hook”? *smash a can on my head*

    I will give it a try, though my first tries ended in having duplicate content in that area if I have a widget placed in that action hook o.O

    Of course I’ll give a feedback on that later after I tested it further.

    However … I keep looking for adding an own hook as I might need it in another place. I found a very very general description about how to add widget areas but I don’t yet know if it will bring me ahead.

Viewing 10 posts - 1 through 10 (of 10 total)

  • You must be logged in to reply to this topic.