Please or Register to create posts and topics.

Using shortcode in custom field

Hello,

I am using your forum and everything works great on a normal page. However, I am also using the [forum category="123"] shortcode in an Advance Custom Fields WYSIWYG field. When I display this field on a page, the forum content is displayed but there are no styles included, it ignores the shortcode category parameters, and clicking on a forum does not use the current page’s URL (it reverts back to the normal page where I originally set it up).

My guess is that because I’m not using the shortcode in the main WordPress content area, it’s not initializing your plugin on the page correctly. Is there a way around this? Any code I can use to force it to initialize it?

I tried manually adding the JS and styles to the page and that fixes the look/layout but not the other two issues (category parameter and URLs).

Thanks for your help!

Hello bmartin,

you can try to set the location into the asgarosforum-object and update the links with some code like that:

global $asgarosforum;
$asgarosforum->options['location'] = $pageID;
AsgarosForumRewrite::setLinks();

But I am not sure if its working.

The problem is that I want to keep all initialization-code away from content/pages which do not contain the forum-shortcode for a better overall-performance. So the forum checks the content of the actual page to see if it contains the shortcode. Is it not possible to put the code into the main-content-area?

If you want to support the development of Asgaros Forum, you can leave a good review or donate. Thank you very much!

Thanks a lot for your help! This site uses the main content area for public info and then shows alternate content to members who are logged in. We want the forum to only show up to members, so that’s why I’m using an alternate field.

The code you provided keeps the links on the current page, however, the links don’t work (don’t load a forum or topic) and the shortcode parameters are still not working. It’s showing all categories instead of the one I’m specifying.

When a “[forum]” shortcode is found, is there a function that is called that I could manually call? I could run it conditionally only when I know there’s a forum on the page. Any other ideas how to make the page act as if it has a forum in the content?

If not, I can put this on a separate page and do custom permissions, I was just hoping to fit it into our current system. Thanks again!

Hello again,

I dont have a good workaround for this at the moment because I assume that a forum is placed inside a page only. What you could do is to modify the includes/forum.php file around line 7 and set a value to true by default:

var $executePlugin = true;

This should ensure that links and styles/scripts are inlcuded on every page. Can you give it a try?

By the way: There is also a build-in option to disable the forum for non-loggedin users. 🙂

 

If you want to support the development of Asgaros Forum, you can leave a good review or donate. Thank you very much!

Thanks, the only thing that’s not working now are the shortcode parameters (shows all categories instead of one).

We’re using this with special permissions for people who have paid for something, so I have to be able to control permissions. If there’s no way to manually call the forum outside of the main content area, I’ll probably just put the forum on a separate page and use the main content area as designed.

Thanks again for your help and for the great plugin, I love how simple and clean it is!

Yeah, thats the same problem. For shortcode parameter I check first, if a pages content contains the shortcode. If so, I parse its attributes.

Those checks have to happen before the shortcode is called (I do this during the wp action) because it has an impact on page-title/etc which is outside of the content-scope. For this I have to know where to look for the shortcode. By default its the page content. I dont really know how I could find a optimal way to analyze other page-parts as well. Basically extensions can create endless possibilities where stuff could be included (terms, meta, custom-post-types, etc) which makes it almost impossible to consider all of them.

If you want to support the development of Asgaros Forum, you can leave a good review or donate. Thank you very much!