I was using Redux option framework before and using it’s feature [data] argument to select page using dropdown to select WordPress page from dropdown, it gives us page ID and we can create anchor links using that page ID in frontend. Now I am trying Kirki customizer framework but I don’t find any option to do so, I somehow found that we can do it by ‘choices’ argument in SELECT option but is being unable to figure out how to do it? Is anyone available to help?
2
Answers
Latest version of Kirki came with solution with Dropdown_Pages control and my problem is solved. Here is example from the kirki documentation:
For more information visit: https://docs.themeum.com/kirki/controls/dropdown-pages/
In Kirki, you can use the ‘choices’ argument to create a dropdown select field in the WordPress customizer. To create anchor links with page IDs, you can follow these steps:
First, ensure that you have Kirki installed and properly configured in your WordPress theme.
Define a section and a control for your dropdown select field in your theme’s functions.php or in a separate customizer configuration file:
In the above code, replace ‘your_theme_prefix’ with your actual theme prefix and adjust other settings as needed.
Create a callback function to retrieve the list of pages for the ‘choices’ argument. You can place this function in your functions.php file or a custom functions file:
Now, you have a dropdown select field in the WordPress customizer that lists all the pages on your site. Users can select a page, and its ID will be saved in the ‘selected_page’ theme_mod option.
To create anchor links using the selected page ID on your frontend, you can retrieve the selected page ID using get_theme_mod(‘selected_page’) and then construct your anchor link accordingly:
Replace ‘your-anchor’ with the actual anchor you want to use.