0

I use the Theme Customizer for a lot of the changes on our WP boilerplate. There are some things, however, that you need an ACF options page for. In an attempt to tie the Theme Customizer into the options pages, I would like to just create a section called Index/Archive Settings, and when you click that, just have a list of hyperlinks that link to each options page. This will tie everything together at least in a way that doesn't leave you playing guessing games where things are. Does anyone know how to do this or if it's possible?

  • Where do you want the links? Do you want the links in your settings pages that link to your customizer settings or the other way around? – stillatmylinux Sep 19 '17 at 3:29
  • @stillatmylinux The other way around. So the customizer would be linking to the settings pages. – Stephen Sabatini Sep 19 '17 at 14:10
1

You need to start by adding the register action and then add section, setting and control. Be sure the change the $my_theme to your theme's slug so this options only show up on your theme.

class SampleAddonCustomizer {

   public $my_theme = 'enter-your-theme-slug-here'; // <- Enter your theme slug here

   public function hooks() {

     $current_theme = wp_get_theme();

     if( $current_theme->template == $this->my_theme ) {
       add_action( 'customize_register', array( $this, 'register' ), 99 );
     }

   }

   public function register( $wp_customize ) {

         $wp_customize->add_section( 'my_custom_section_links', array(
           'capability' => 'edit_theme_options',
           'priority'   => 50,
           'title'      => __( 'Index/Archive', 'sample-customizer-addon' )
         ) );


         $wp_customize->add_setting(  'special', array(
           'capability' => 'edit_theme_options',
           'type'       => 'hidden',
           'autoload'   => false
         ) );

         $wp_customize->add_control( 'special', array(
             'label'   => 'Links to settings',
             'description' => $this->get_links(),
             'section' => 'my_custom_section_links',
             'type'    => 'hidden',
         ) );
   }

   public function get_links() {

     $links = array(
       array('url' => 'http://example.com/', 'text' => 'Example', 'desc' => 'Just an example'),
       array('url' => 'https://yahoo.com/', 'text' => 'Yahoo!', 'desc' => 'More entertainment'),
       array('url' => 'https://google.com/', 'text' => 'Google', 'desc' => 'Just Search'),
       array('url' => 'https://bing.com/', 'text' => 'Bing', 'desc' => 'Nice pictures'),
     );

     $html = '';

     foreach ($links as $link) {
       $html .= '<p>'.$link['desc'].'<br>'.PHP_EOL;
       $html .= sprintf('<a href="%s">%s</a>', $link['url'], $link['text']) . '<br>' . PHP_EOL;
       $html .= '</p>'.PHP_EOL;
     }


     return $html;
   }

 }

 $sampleAddonCustomizer = new SampleAddonCustomizer();
 $sampleAddonCustomizer->hooks();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.