Get page slug with Fluent Forms

tdrayson

A member in the Fluent Form facebook group wanted a way to get the page slug.

We are going to create a smartcode that returns the page slug for the page we submit the form on.

Copy and paste the snippet below into functions.php or code snippet plugin.

PHP

        add_filter('fluentform_editor_shortcodes', function ($smartCodes) {
    $smartCodes[0]['shortcodes']['{page_slug}'] = 'Page slug';
    return $smartCodes;
});

add_filter('fluentform_editor_shortcode_callback_page_slug', function ($value, $form) {
    
    global $post;
    return $post->post_name;
    
}, 10, 2);
      
Copy

Once you have added the snippet, you should see the smartcode display in the dropdown menu under default value.

screenshot 2022 12 02 at 13.47.47

👋🏻 Weekly Tutorial Digest

I send out a weekly newsletter with links to new tutorials written in the last week, you can subscribe below.

Newsletter

🔒I won't send you spam, I promise