• Resolved cambro

    (@cambro)


    Hello,

    I’m working with the Better Notifications for WP (BNFW) plugin. I’m trying to introduce a custom shortcode.

    I have another plugin that allows for the creation of custom shortcodes, but BNFW doesn’t seem to recognize those.

    After some research, I came across instructions (https://betternotificationsforwp.com/documentation/adding-custom-shortcodes/) within the BNFW documentation that outlines how one might create their own custom shortcode that will work with BNFW.

    I tried adding the following code in wp-includes/function.php as instructed.

    function bnfw_shortcode_HelloWorld() {
    $HelloWorld = “Hello World”;
    return $HelloWorld;
    }

    add_shortcode( ‘HelloWorld’, ‘bnfw_shortcode_HelloWorld’ );

    When I save and load the site, I get this error: Fatal error: Uncaught Error: Call to undefined function add_shortcode() in…

    I’m not sure what I’m doing wrong. I’m new to Word Press / PHP. I’m probably not seeing what someone with more experience might be seeing. Any help / suggestions I can get are appreciated.

    Thanks

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter cambro

    (@cambro)

    Update… I created a new WP site using one of the stock template options. I then figured out how to make a simple plugin. In that plugin, I place the HelloWorld functions as posted previously.

    The shortcode behaves as expected on a web page. However, it simply displays the shortcode “[HelloWorld]” bit in the email notification rather than “Hello World” as expected. Not sure why.

    Any ideas / suggestions?

    Thanks

    Plugin Author bnfw

    (@voltronik)

    Hi @cambro,
    Thanks for your message.

    With regards to your first message, you need to add this to the functions.php file inside your theme or child theme.
    I can’t provide support for custom code so you may need a developer to help you with getting the PHP correct for your desired output. Once working though, it should work with BNFW.

    Thread Starter cambro

    (@cambro)

    Thanks for the reply.

    I created a new WP site and selected the stock Twenty Twenty-Four them. Then, I placed this code in the function.php.

    function?bnfw_shortcode_futuredate()?{$future_date?=?date(?‘F?j,?Y’,?strtotime(?‘+1?year’?)?);return?$future_date;}
    add_shortcode(?‘future_date’,?‘bnfw_shortcode_futuredate’?);

    I can use the shortcode in a webpage without any errors. However, when I place in a BNFW new member notification and test it by creating a new user, the email received does not render the date as expected but merely the “[future_date]” as seen below.

    Site Title: My WordPress
    Site Tagline:
    Site URL: <redacted for post>
    Site Admin Email: <redacted for post>
    Current Date: April 13, 2024
    Current Time: 12:57 am

    [future_date]

    Is it fair to think that this should work within BNFW? If not, why?

    Thanks

    Plugin Author bnfw

    (@voltronik)

    Hi @cambro,
    I think this is becuase you need to use it in a post, page, or custom post type notification in order for this to work.

    Please try that and let me know how you get on.

    Thread Starter cambro

    (@cambro)

    That worked and thank you!

    I guess using a custom shortcode with the New User Notification is not possible at this time? Seems a bit odd.

    Thanks for the help.

    • This reply was modified 11 months ago by cambro.
    Plugin Author bnfw

    (@voltronik)

    Hi @cambro,
    No problem.

    There probably was a reason why it wasn’t possible with the user registration notifications but if it’s possible to change this, I’ll do so in a future update.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Adding Your Own Custom Shortcodes’ is closed to new replies.