I installed a geotargeting plugin with different information for different cities and countries, in php it looks like this:

echo do_shortcode("[wt_geotargeting country_show='RU'] Вывод текста для России [/wt_geotargeting]"); 

Suppose I do not want to write information about the shortcode, I create a variable and put it in the code, it goes like this:

 $block_1 = 'Блок 1'; echo do_shortcode("[wt_geotargeting country_show='RU'] $block_1 [/wt_geotargeting]"); 

Actually, the question is - the client needs to change the contents of the variable independently (insert pictures, text), how can you access the variable through the admin panel?

  • one
    You can create: 1) additional settings in the theme settings; 2) an option, the value of which is changed on a separate (or already existing) page in the admin area; 3) Metabox for the type of post or category that will store the user field. Depends on the logic of using this "variable". - Ponio

1 answer 1

The crutch will be a crutch, but “arbitrary fields” can be created and substituted into your variable. And from the admin he will rule and you less hemorrhoids: DDDD

  • My friend, share your advice, I don’t already know where to look, I need to display different content, in the custom fields they all output a string with an array - waspmax1
  • one
    Advanced Custom Fields: wordpress.org/plugins/advanced-custom-fields ; Essentially short code: <? php echo do_shortcode ('[acf field = "title_first (field name)" post_id = "799 (go to an entry for which this field is)"]'); ?> And try to do it like this: $ block_1 = <? Php echo do_shortcode ('[acf field = "title_first (field name)" post_id = "799 (go to an entry for which this field)"] "); ?>; advancedcustomfields.com/resources/creating-a-field-group - documentation. Bun - wp-book.ru/… - Lieutenant Jim Dangle
  • Thank you very much! It works, but the problem remains with the images, that is, if you select WYSIWYG Editor in the field type, the content is excellent, but if you select an image, it displays an array with information about the image, tried to output via $ block ['url'] - does not display - waspmax1
  • I do not know whether it will work out or not. There is such a code for the editor, only then you need to upload pictures of at least a hundred thousand to the editor. <? php if (get_field ("redactor WYSIWYG field name")):?> <? php preg_match_all ("/ <img [^>] + src \ s * = \ s * [\" '] \ /? ([[ ^ \ "'] +) [\"'] [^>] * \> / ", get_field (" redactor "), $ images);?> <? php if (! empty ($ images [1])) :?> <? php foreach ($ images [1] as $ img):?> <div> <img src = "<? = $ img?>" alt = "" /> </ div> <? php endforeach ;?> <? php endif;?> <? php endif;?> - Lieutenant Jim Dangle
  • If you select an editor in the field type and upload images via "add media file" - they are output, I need to output them through the field of the "image" field - waspmax1