Support

Account

Home Forums Add-ons Options Page Options Page Shortcode

Solved

Options Page Shortcode

  • I have a wysiwyg field in an Option Page. I want to create a shortcode for this but am having a heck of a time. This is for a disclaimer that needs to appear in various places throughout my site. I’d rather not build separate templates for each place.

    I followed the instructions on how to build a shortcode I found in the WordPress codex, and if I have the result 'Hello'; it works so I know the shortcode is being read.

    I need to get the content from the ACF Options Page into it.

    I have a tried a bunch of stuff, but most of it gives me a white screen or nothing.

    This does not work when added to functions.php:

    function DisclaimerShortcode() {
    	return the_field('gpo_disclaimer', 'option');
    }
    add_shortcode('disclaimer', 'DisclaimerShortcode');
  • the_field() echos the content of the field, the same way that the WP function the_title() echos the title. You need to use get_field() when you don’t want the value echoed where the function is called.

    function DisclaimerShortcode() {
    return get_field(‘gpo_disclaimer’, ‘option’);
    }
    add_shortcode(‘disclaimer’, ‘DisclaimerShortcode’);

  • Yeah, I’m an idiot. I actually had that exact code in there an nothing showed up. Why? Because I failed to SAVE the content I entered in the Option Page area. Stupid. Thanks. It is working perfectly.

  • It happens to all of us, like editing a page file over and over again trying to figure out why nothings changing and finally figuring out that you’ve been uploading the wrong file over and over again. Doesn’t matter how long you’ve been doing this, we all have those moments. I had one of those moments today myself 🙂

  • Thanks John, for the help and the understanding of those “doh!” moments.

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

The topic ‘Options Page Shortcode’ is closed to new replies.