Hooking into filters

This support request was posted in Smart by xaraboo

Request ID #34846 Resolved
  • Juanfra Aldasoro

    Hello,

    Thank you for writing.

    The nice_post_footer_meta_template only gives the template in which the footer meta will be displayed. It doesn’t have an “echo” parameter. Would you please tell me what you are doing exactly and what you want to do?

    Thank you,
    Juan.

    I would like to be able to remove the file, comment count, and tags from the footer meta. To solve the problem, I simply edited the `child-theme/includes/template-tags.php function nice_post_footer_meta( ) and set the $defaults->echo = false;

    Juanfra Aldasoro

    Hi,

    Thank you for the follow-up.

    The file includes/functions.php cannot be overridden on a child theme basis. It has sensitive functions in order to make the theme work.

    The whole idea of filters is that you can add hooks to them from outside the function in which they are declared. So, to achieve what you want to do, it would be better to define something like this in the smart-child/functions.php file:

    <?php
    //* Do NOT include the opening php tag
    add_filter( 'nice_post_footer_meta_args', 'nice_post_footer_meta_my_args' );
    function nice_post_footer_meta_my_args( $args ) {
    $args['echo'] = false;
    return $args;
    }

    You can read more about hooks in the WordPress documentation portal: https://codex.wordpress.org/Plugin_API#Hooks:_Actions_and_Filters

    Best,
    Juan.

    Thank you! That’s exactly what I was trying to accomplish.

    Juanfra Aldasoro

    Hi,

    Thanks for the follow-up.

    That’s great 🙂

    Have a nice day,
    Juan.

    So I get the principles behind add_filters, but say for example, how do I determine what I’m supposed to pass to turn off the post_author and date in the nice_post_meta_template?

    I see where it defines $nice_post_meta_tpl = '[post_author_posts_link] [post_date [post_categories] [post_comments] [post_edit]'; but I’m not understanding how to I would change that for the entire template.

    Thanks

    Juanfra Aldasoro

    Hi,

    Thanks for the follow-up.

    The acronym tpl stands for template. So, the hook nice_post_meta_template can be used to alter that template. The elements with square brackets are used as placeholders.

    For example, if you want to remove the author and date, you can redefine the template to only include this:

    $nice_post_meta_tpl = '[post_categories] [post_comments] [post_edit]';
    

    (Please note how I’ve removed the two first elements).

    Please be sure to use the appropriate filter and don’t modify the function in includes/template-tags.php

    Best,
    Juan.

    Thank you., I figured it out.

    Juanfra Aldasoro

    My pleasure! the magic of filters.

    Have a nice day,
    Juan.

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

This topic is marked as resolved

Only the topic author can re-open this thread.

Login to your Account

Welcome back! Please log in to your account by filling the fields below:

Not a member? Create a free account.

Create a Free Account