Add Content to Page without shortcodes

The site I'm working on has a couple of pages that needs to be filled with different content elements like text image combinations, sliders, lists of content, etc. The client would need to re-order these content blocks, add new ones and so forth. Every content block would be piece of content (post or custom post type) or a list of content.

From what I understand I have 2 options:

  1. Use an complex plugin to drag and drop predefined content
  2. Use shortcodes

From a developing standpoint I would rather not leave all the logic to a third party plugin. It seems I would lose some of the control over the templating?

But shortcodes don't seem like an acceptable solution for any customer, really, because they are too technical.

Any suggestions? Is there a best practice?

Topic custom-content shortcode page-template templates custom-post-types Wordpress

Category Web


I evaluated the different options and went with a plugin "Page Builder". While the technical aspects are not great (e.g. data persisting: all content gets serialized) is was the only option to give me enough flexibility and enough comfort so that the customer could make changes to the structure of each page.

Migrating from dev to stage to live was also a pain due to the serializing and only possible with yet another plugin (duplicator).

Thanks everyone for the input!


You could consider using the page templates. For the example im going to use a contact page. "contact-page.php"

You can then write in the code you need for the template. To keep the flexibility look up how to use the Customizer (if you're not familiar with it) and use this in the template page to let the admin modify the page content without having to look at the code. This is how I've done my templates.


While shortcodes by themselves are linked to functions, I think you could use them effectively in combination with templates and a metabox for their input data. eg:

add_shortcode('content-box','content_box_function');
function content_box_function() {
    global $post;
    $title = get_post_meta($post->ID,'_content_box_title',true);
    $content = get_post_meta($post->ID,'_content_box_content',true);
    get_template_part('templates/content','box');
}

/wp-content/themes/theme-slug/templates/content-box.php

<div class="content-box-container">
    <div class="content-box">
         <h3 class="content-box-title"><?php echo $title; ?></h3>
         <div class="content-box-content"><?php echo $content; ?></div>
    </div>
</div>

Then add a metabox to the post writing screen to allow the user to select/define the meta values to go with the keys you are using for each content block shortcode.

Gives you the advantage of allowing the shortcode to be ordered/placed anywhere in the content, and still have other content there as needed be, but the templating (and related styling) could be worked out already for the predefined content block types.


This is an interesting question, though a bit too broad for a Q&A model. Here is what I would do:

  1. Create a custom post type, where each post is a block of content
  2. Create a second custom post type for pages that are assembled from blocks of code. In stead of a content field, create ten drop down fields (or more if there are more blocks possible on a page). For the select options in the dropdown, take the title of all posts in the first custom post type. In this way any new block of content will automatically become available for assembly.
  3. Create a template for the second post type, that loops through all drop down fields and assembles the content from the first custom posts.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.