Press enter to see results or esc to cancel.

Global custom fields

Ad Inserter settings are accessible only to administrators or users who have the manage_options WP cappability. Normally you would need to grant admin access to anybody who needs to update ad codes or the text that is inserted via Ad Inserter. Global custom fields are a simple solution to this problem. They allow other users without admin access to edit custom fields with the code or text that is used in Ad Inserter blocks or elsewhere in the site. With custom pages and fields you can create new, customized sub-admin pages to edit global fields.

Ad Inserter global custom fields are universal pieces of data (ad codes, HTML code, text, or anything that can be inserted) that appear across the entire site (globally) and are managed in one central location. The site administrator can define page title, menu position and access level. They are a kind of option pages with sets of custom fields that are available globally throughout the website and don’t belong to any particular post. The data from the global custom fileds can be accessed via shortcode or PHP function and can easily be used in Ad Inserter blocks. This way administrators can keep restricted access to plugin settings while allow other users like editors or authors to edit common data or codes that are used elsewhere on the site.

To use global custom filelds you need to define pages and fields and then use shortcodes or PHP functions to access field data.

Please note that WordPress (and Ad Inserter) supports also custom fields that can be defined for each post. Those custom fileds are not global, i.e. they can be used only inside the post where they are defined. This page describes how to configure and use global custom fileds that can be used globally – in Ad Inserter and on any WordPress post or page.

Pages for custom fields

With custom admin pages (sometimes named also options pages) you define custom settings pages where the users will be able to edit custom fields. Go to general plugin settings ( tab ⚙/ tab General / tab Pages for custom fields).

For each page you need to define a name for the page. The same name will also be used for the menu item so make ti short. Then you need to define menu position where the link to this page will be placed. You can choose either Top menu (link to the page will be displayed as top menu item in the left menu bar) or submenu on any of the existing top menu items. You also need to define priority for the menu item – menu items with lower numbe will appear before menu items with higher number. Finally, you need to define access level for the page. Choose one of the available user roles (Editor, Author, Subscriber, etc.).Each page you would like to use needs to be enabled with the checkbox in front of the page name. Disabled pages will not appear in the menu and can not be accessed.

ad inserter pages for custom fields

PRO In addition to user roles, in Ad Inserter Pro you can also grant access to a single WP user and further limit access to the page with custom fields.

Global custom fields

On the tab Global custom fields you define the fields that the users will be able to edit. You need to set a name for the field and select the page where this field will be edited. The name of the field will be displayed above each field on the page. Each global custom field you would like to use needs to be enabled with the checkbox in front of the field name. Disabled fields will not appear on the pages.

ad inserter global custom fields

After you are done save settings and reload the page so the created pages pages will be available for custom fields.

Editing global custom fields

Now when the page with custom fileds is created you can define/edit custom fileds. 

Please note that after you save settings for custom fileds you need to reload the admin dashboard so that the new settings are loaded and the new menu is created. 

For the example above you should now get a new submenu Post ads in the Settings WP menu. Clicking on the Post ads menu should open a page with custom fields like the one below. Enter the codes and save settings.

ad inserter page with custom fields

Accessing global custom fields

Ad Inserter global custom fields can be accessed via shortcode or PHP function.

Via shortcode the field (defined end enabled on Pages for custom fields and Global custom fileds) can be accesses via field number of field name. For example:

[ADINSERTER global-custom-field="1"]

[ADINSERTER global-custom-field="Before content"]

The shortcode when expaned will return the code or text saved for the custom field 1 named Before content. This is the easiest way to use global fields in Ad Inserter blocks

To access custom field from PHP code you should use PHP function adinserter_global_custom_field () with field number or field name as the parameter:

<?php if (function_exists ('adinserter_global_custom_field')) echo adinserter_global_custom_field (1); ?>

<?php if (function_exists ('adinserter_global_custom_field')) echo adinserter_global_custom_field ("Before content"); ?>

Of course, global fileds defined in Ad Inserter can be used anywhere on the website, in the theme or in other plugins.