In this post i’ll teach you how to create a new custom content box on every edit post screen.
The new meta box enables you to add any type of unique content before your primary sidebar of every post you publish.
Here’s what it looks like on the front end of 1 single post:
And here’s the new box which is added to all your edit post screens:
You can use this solution to:
- Display different adverts on different posts, above the fold.
- Any type of content including videos, text, HTML etc. before your sidebar
There’s only 2 steps you need to follow to add your own mini sidebar:
- Add PHP code to your child themes functions file.
- Create your custom field using the incredible Advanced Custom Fields (ACF) plugin.
Step 1
There’s only 4 lines of PHP code you need to paste at the end of your child themes functions.php file.
No CSS code is needed unless you want to style your custom field differently to what your themes default primary sidebar uses.
Step 2
Once you install the ACF plugin, click to enlarge this image and use exactly the same settings as this screenshot includes.
That’s all you need to do in order to add a new box which enables you to display different content above the sidebar on different posts on your site.
Thank you for this! I used it and it works great! I was wondering if there’s a way to code in a title? (I’m new to this!)
Thank you Brad, the custom sidebar works great and your instructions were concise and easy to follow.
Thanks for the comment Dave.
Hi Brad
Nice and neat and oh so useful for adding unique content for each post.
Agree with Zimbrul…
“And I think is smarter solution than using Simple Sidebars as you can implement this on a post by post basis without ending up with tens of sidebars…”
Simple sidebars would be useful if you use the same sidebar for a particular post category – that would limit the number of sidebars needed.
That’s right Keith nd you can easily change the hook, conditional tag and field type to suit your needs.
This is a neat trick! And I think is smarter solution than using Simple Sidebars as you can implement this on a post by post basis without ending up with tenth of sidebars (one for each post if required).
So this is the way you are doing the index of your tutorials on this site? I thought you either use Simple sidebars or some plugin like Widget logic.
Simple sidebars is a good solution for creating a handful of custom sidebars but not if you want totally unique content on each post or page.
That’s where custom fields take over and also enable you to choose from a large range of field types using the ACF plugin.
I agree with you, would be quite uneconomical to have such many custom sidebars.
I guess we can use the same technique like in this tutorial to build an “after post” custom content block
Exactly. Simply change the hook
Hi Brad! Nice feature.
I see you are using genesis_get_custom_field() from genesis instead the get_field() from ACF or the get_post_meta() from WordPress. Why is that? Just a preference, or it gives you more options or flexibility than the others?
Just for something different.
Nice!