0

I am having trouble changing the slug of my archive page. The goal is to create a page that can be edited from the back end of WP with the slug speakers, but that has already been taken by the archive page. This has to be client friendly so it can't be only editable in the php. I am willing to do whatever anyone thinks is the best idea for this.

Ideas:

  • removing the archive page all together
  • rewriting the slug to be speaker or presenter, that way I can create a page with the speakers slug
  • making the archive page editable

Does anyone have ideas on this? I created a custom post type and tried setting the has_archive to false and creating a slug array but it didn't work. And if you just set it to 'false', it pulls a list of regular posts.

Thank you!

1
  • Have you considered not using a page at all?
    – Tom J Nowell
    Jul 8, 2015 at 15:14

1 Answer 1

0

There's an easier way, don't bother with the page at all.

Instead, store the content inside an option or theme mod, and use the settings API/customiser to edit the content.

To turn the textarea holding the content in your form into a full editor, use the wp_editor function to get a wysiwyg editor that looks and works like the edit page screen. Use get_option or get_theme_mod to retrieve the content on the frontend, and pass it through the the_content filter for oembeds shortcodes and paragraphs to work.

For example, here is how to add an editable footer content area to the customizer ( taken from here )

add_action( 'customize_register', 'your_customizer' );
function your_customizer( $wp_customize ) {

    $wp_customize->add_section(
        'appearance_settings',
        array(
            'title' => __('Appearance Settings'),
            'description' => __('Modify design options'),
            'priority' => 120,
        )
    );


    $wp_customize->add_setting( 'footer_content',
        array(
            'default'=>'default text'
        ));

    $wp_customize->add_control(
        new Example_Customize_Editor_Control(
            $wp_customize,
            'footer_content',
            array(
                'label' => 'Footer content',
                'section' => 'appearance_settings',
                'settings' => 'footer_content'
            )
        )
    );
}

Here's the editor content control:

if(class_exists('WP_Customize_Control')){

    class Example_Customize_Editor_Control extends WP_Customize_Control {
        public $type = 'textarea';

        public function render_content() {
            ?>
            <label>
                <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>

                <?php

                $content = $this->value();
                $editor_id = $this->id;
                $settings = array( 'media_buttons' => true, 'drag_drop_upload'=>true );

                wp_editor( $content, $editor_id, $settings );

                ?>
            </label>
        <?php
        }
    }
}

Here's some JS to update the preview pane:

jQuery(document).ready(function($){
    $('textarea[name="footer_content"]').attr('data-customize-setting-link','footer_content');

    setTimeout(function(){

        var editor2 = tinyMCE.get('footer_content');


        if(editor2){
            editor2.onChange.add(function (ed, e) {
                // Update HTML view textarea (that is the one used to send the data to server).

                ed.save();

                $('textarea[name="footer_content"]').trigger('change');
            });
        }
    },1000);
})

And here's some PHP to load the js:

function your_customize_backend_init(){

    wp_enqueue_script('your_theme_customizer', get_template_directory_uri.'/customizer/customizer.js');
}
add_action( 'customize_controls_enqueue_scripts', 'your_customize_backend_init' );
4
  • Thank you for the quick response, Tom! That's a super neat function! For those interested in seeing what that looks like, here's an image: postimg.org/image/f4a9vibkx. Though that's unfortunately not what we're looking for with this page. I'm pretty confident it will need to be in page form. I'm currently hosting snidgets (from WP Edit Pro) where they can go in and edit the content there if worse comes to worse, but I'd much prefer it in page format. Jul 8, 2015 at 16:02
  • What does a page provide that a visual editor in the customiser doesn't?
    – Tom J Nowell
    Jul 8, 2015 at 16:55
  • It needs to be client friendly. Jul 13, 2015 at 16:54
  • That doesn't sound client friendly, especially if the page gets deleted by accident, or if someone renames the page, or its ID gets changed, gets set as a draft, moved to trash, etc, and the client phones you up wondering why their website's broken. A customiser editor allows them to preview the change without publishing, puts it next to all the other options, and can't be broken by accident
    – Tom J Nowell
    Jul 13, 2015 at 18:18

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.