I am building a Wordpress/Woocommerce site, and developing a plugin for it.

In the plugin I am including some PHP html templates and hooking them into Wordpress in various ways.

Is there a way to visually compose and store these page snippets/sections somehow so that they can be viewed and edited in admin, through a visual composer?

I am envisioning something like Wordpress' page designer/editor, except just for page sections/snippets.

Thanks in advance!


I found that this can be done simply by using Wordpress' Page editor. Nothing else is needed:

  1. Compose the content in Wordpress' Page editor
  2. Save (but don't publish)
  3. In your code, retrieve the saved content

By ID:

$post = get_post($id);
$content = apply_filters('the_content', $post->post_content); 
echo $content;

Or by page title:

$title = 'page title';
$page = get_page_by_title( $title );
$content = apply_filters('the_content', $page->post_content); 
echo $content;

Note that apply_filters is used in case there is a plugin somewhere that wants to "apply filters" to the_content - it's good for forwards compatibility.

| improve this answer | |

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.