I was assigned to create a simple Wordpress slider plugin, using a custom post type and Repeater fields from Advanced Custom Fields. The code of this is in slider-custom-types.php

I created a single page (single-slider.php) in the theme I'm working on, so I could define the base markup to display the content properly. These two files are in this gist: https://gist.github.com/JulianBonilla7/5257788444f078107faf5cb97580ee12

So, I want to be able to display an instance of Slider post type (with the HTML markup) into any page or post (from templates code, and from admin using shortcodes), but I have no idea of how should I do that. The idea is to make it work like Revolution Slider does, this one gives you the shortcode to place it in the page editor, or generates PHP code so you can put it directly in the template.

I'm just starting to work in Wordpress and I've searched for information but I don't understand much. I'd love if you can guide me on how to do this task.

  • Extract the slider display in to a function and hook that function to a shortcode.
    – bravokeyl
    Commented Oct 10, 2016 at 17:21
  • For example, look at this Slider just to get a basic idea but this can be greatly improved.
    – bravokeyl
    Commented Oct 10, 2016 at 17:24
  • Also take a look at existing open source sliders as how they are doing it.
    – bravokeyl
    Commented Oct 10, 2016 at 17:24
  • I did it based on your code, thanks! But I agree it can be better, gonna check out other projects to refactor the code. Commented Oct 11, 2016 at 0:39

1 Answer 1


Slider: You will need to create a custom taxonomy (ex: slider) that you will use as an instance of a slider and use the custom post type (ex: slide) as a slide of each slider. There are multiple ways of tackling this but this is the easiest way I can think of.

Shortcode: For the shortcode you will have to create a shortcode through which you can parse the variables that will make your slider customizable and adaptable to each post. To achieve this you should follow the Shortcode API from Wordpress codex

Quicktags: You can add quicktags into the mix if you want to make a UI for the user to help them set the correct parameters they need. This will programatically add the shortcode into the post.

With this combination you can tell the shortcode to extract X posts (or slides in this case) from a specific term of your custom taxonomy and then use something like bxSlider for the slider itself. This way you can specify which slider you want to display where and parse the parameters you need.

The only way to achieve this properly if you follow this technique is by using term meta for the slider itself and post meta for each slide. Seems like advanced custom fields support both of these.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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