Support » Plugin: Recent Posts Widget With Thumbnails » Add Custom Text using Hook

  • Resolved Mwale Kalenga

    (@mwalek)


    Guten Tag,

    Thanks for this great plugin. I would like to add my own text after categories are listed using “rpwwt_list_cats”. This is not working, how can I do this?? Thanks

    My Code:

    function rpwwt_custom_text() {
        echo 'hello world!';
    };
    add_action('rpwwt_list_cats', 'rpwwt_custom_text');

    Kind regards,
    Mwale

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Martin Stehle

    (@hinjiriyo)

    The hook 'rpwwt_list_cats' takes effect in the categories selection box of that plugin on the backend’s Widgets page.

    Recently there is no such hook for the category lists on the frontend. Would a new hook like
    echo apply_filters( 'rpwwt_categories', $this->get_the_categories( $r->post->ID ) );
    be the right tool for you?

    Thanks for your quick response Martin.

    I’m not sure.

    What would the code for me to add my own ‘hello world’ text look like with the new hook.

    Thanks in advance,
    Mwale

    Plugin Author Martin Stehle

    (@hinjiriyo)

    You’d add the same code with another hook name:

    function rpwwt_custom_text() {
        echo 'hello world!';
    };
    add_action('rpwwt_categories', 'rpwwt_custom_text');

    I pasted the exact snippet in my functions file. Nothing happens on the front-end. Any idea why?

    Plugin Author Martin Stehle

    (@hinjiriyo)

    With the new version 6.7.0 you can take advantage of the new hook rpwwt_categories. Some advices:

    1. Do not use any echo statement in the filter function. Instead append all strings to a new one and return it.
      • To echo the category list store it in a variable as the first parameter of the filter function and add it to the return string.

    So a correct way to use the filter is:

    function rpwwt_custom_text( $category_list ) {
        return $category_list . '. Hello world!';
    };
    add_action( 'rpwwt_categories', 'rpwwt_custom_text' );

    If you’d like the new feature I will be glad about your review.

    Thanks so much Martin!

    It really is an amazing plugin, 5 stars from me!

Viewing 6 replies - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.