Community Forums › Forums › Archived Forums › General Discussion › Automatic CTA snippet at bottom of post?
- This topic has 29 replies, 4 voices, and was last updated 10 years, 1 month ago by mborger.
-
AuthorPosts
-
May 25, 2013 at 1:58 am #42575mborgerMember
Hi folks. Is there a Genesis way or third-party plugin that automatically places a selected snippet of code at the end of a post based on some author-defined criteria? For example, my site is based on real estate investment. I would like to end all posts related to selling a house with a block of text and a graphic call to action, i.e. "interested selling? click here to download your free e-book". If it's a about buying a home, then the same thing applies but with a different call to action. Hubspot does this all the time (blog.hubspot.com) and it looks great and helps convert visitors into customers.
Ideally, I could categorize/classify/tag a post during its creation and the associated snipped automatically gets placed at the end, but I know that might not be possible. Just looking for potential answers here instead of manually creating them every time. Thank you.
May 25, 2013 at 2:17 am #42576Brad DaltonParticipant1. You could echo in the code using a custom function with conditional tag however it will be the same for all posts
2. You can create a widget area and do the same thing but it will be the same code
3. You can create a custom field with custom meta box enabling you to use a different code snippet on different posts in the same position.
Let me know which one suits your needs and i will supply the solution.
May 25, 2013 at 12:09 pm #42612mborgerMemberHi Brad. Option #3 sounds like what I'm looking for. Thanks a lot for helping me with this. Most likely this will help out other users as well.
May 26, 2013 at 1:56 am #42660Brad DaltonParticipantJune 13, 2013 at 4:53 am #45641mborgerMemberThanks Brad and sorry for the delay - I'm in Japan at the moment.
I added the code to the end of the functions.php and got this error message:
Fatal error: Cannot redeclare custom_field_after_posts() (previously declared in /home/mborger/public_html/wp-content/themes/agentpress-two/functions.php:251) in /home/mborger/public_html/wp-content/themes/agentpress-two/functions.php on line 265I get what it means conceptually but I'm not sure technically how to get around it.....? I had to revert the php file to its previous version.
June 14, 2013 at 4:41 am #45830Brad DaltonParticipantYou must have added the code twice which won't work as all functions need to be unique.
You will need to check your child themes functions file or rename one of the functions.
June 14, 2013 at 6:16 am #45853mborgerMemberYou were right - I had it in there twice. I took care of that, installed your plugin with some test 'blah blah' text of the wysiwig type but don't see it anywhere on the post. I created a new category, added my most recent blog post to that category (bigrockinvestments.com/summer-real-estate-season/) and cleared caches, but it's not showing up. Is there a step I'm missing? Another rule I need?
June 14, 2013 at 7:17 am #45867Brad DaltonParticipantThe code simply creates the function which hooks in with the native WordPress custom field functions. You'll need to add the content in the value field.
You can use the built in custom fields which appear on each edit post screens below the editor. You should see a custom field there named afterpost which you can select and then add the content in the value field to be displayed after that post.
No need for a plugin unless you want a custom meta box
June 14, 2013 at 7:32 am #45878mborgerMemberConfused but trying to follow along. I don't see any custom fields section at all. In the Layout Settings section, I see Custom Body Class and Custom Post Class - that's it.
Below that I have a separate section called Sellerpost only because, in the plugin, I created a field group with one field called 'Sellerpost'. The only Rule is that the Category must be Sell_House, which I attached my test post to. Doesn't show.
But ultimately I don't need a custom meta box (by meta, I assume you mean the section in the admin panel), so maybe I don't need the plugin? What I just want are to create a few (3 to 5) pieces of code that, depending on some flag of the post, will show up at the end, i.e. every post tagged/categorized/other-type-of-flag as a 'sell' type post will get the associated 'sell' block of code. 'Buy' posts get the 'buy' piece of code.
June 14, 2013 at 8:16 am #45890Brad DaltonParticipantGo to screen options top right of edit post screen and check the box to display custom fields.
Don't think you need the plugin.
June 14, 2013 at 7:17 pm #46009mborgerMemberOk so I see my 'sellerpost' field in the Custom Fields section. The Value field is just blah blah text. But I don't actually see anything on the post.
The only other custom field is the Disqus with a numerical string in the Value field box.
So do I need to put something else in the Value box? Right now it's just text -- I ideally want text/images/formatting, etc, just like Hubspot does at the end of their blog posts. FYI, when I created the custom field via the plugin, I gave it the wysiwyg type.
June 15, 2013 at 4:12 am #46034Brad DaltonParticipantThe code i provided works with the native custom field functions built into WordPress, not the plugin. If you wanted code to use with the plugin, you would need to ask on the ACF forum for that code. Or write the code yourself using the smaple code ACF provides on their website.
If you want to use the native WordPress custom fields, please deactivate the plugin, select the field name from the drop down menu and add your content to the value field.
Based on the code i supplied, this will display your content after the post content for that specific post only.
By the way, what name are you using for the field name? The code i supplied uses afterpost which is the name you need to select from the drop down menu in the native custom field meta box.
June 15, 2013 at 5:57 am #46048mborgerMemberOk, making progress. I had to change the field name to afterpost. But if you look at bigrockinvestments.com/summer-real-estate-season/ and see it at the bottom, I'd rather it be above the "Filed Under" box instead of below it.
However, another concern is that with this method, this needs to manually done for every post. Let's say I have 30 posts regarding selling a house all using the same field code at the end of the post with a CTA to a seller squeeze page. In the future if I decide to change that text, image or CTA, I'll need to update it for every post manually and individually. This is what I want to avoid -- I want to set it once so that if I want to change the code in the future (ex. URL of squeeze page), I only have to change it one place. So if all posts regarding selling are somehow given a tag or category 'sell-house' then they get the appropriate code, those regarding foreclosure get a 'foreclosure' code, etc. Perhaps I even segment it into 'sell-house-1' and 'sell-house-2' and switch it up accordingly with the simple use of one tag or another. Then when I write a new post, all I have to do is assign it with the proper tag or some other means so that it automatically pulls the chosen code block.
June 15, 2013 at 6:17 am #46051Brad DaltonParticipantIn that case i suggest you use a custom widget.
Custom fields should be sued for adding different content in the same theme position.
How will you group them together? Tag or Category?
June 15, 2013 at 6:23 am #46054mborgerMemberI don't know -- I'm kind of at the frontier of my techie/coding knowledge here. I was thinking to create separate categories: Seller, Foreclosure, Buyer, Investor and then assigning each post to the appropriate category. I do want it in the same position on each post -- at the bottom of the body text; I don't want it as a widget because my width in the sidebar is limited -- if it's in the body then I have the full width to work with. Again, I'd like to mimic what Hubspot does at the bottom of each of their blog posts - I just don't know how to do it without manually editing the custom field for each individual post.
Seems to me like a custom field would be the right answer as long as I can have a previously coded set of code blocks that it can automatically pull from based on the appropriate category.
I'm open to suggestions.
June 15, 2013 at 6:25 am #46055Brad DaltonParticipantPlease copy this code from the view raw link and paste it at the end of your child themes functions.php file using a code editor.
Code not displaying? Grab it on Github.
This widget outputs your content after posts tagged with sell-house-one.
Please remove the code which i supplied for creating a custom field.
Does this code provide the solution you want @mborger?
June 16, 2013 at 2:03 am #46223mborgerMemberThanks for helping me through this. Can it be done via category instead of tag?
And do I still need to add a custom field? Where does my actual code for my block go for my design?
June 16, 2013 at 4:09 am #46227Brad DaltonParticipantYes. Change the conditional tag:
if ( is_single() && has_tag('sell-house-one') && is_active_sidebar( 'sell-house-one' ) ) {
to
if ( is_single() && in_category('sell-house-one') && is_active_sidebar( 'sell-house-one' ) ) {
You won't need the custom field if you only want to display the same content after posts in the same category.
Please clarify this question as i do not understand
Where does my actual code for my block go for my design?
June 16, 2013 at 4:26 am #46229mborgerMemberOk - updated that line. What I mean by the question is: where do I place the chunk of code for the actual content I've designed and wish to place at the bottom of all seller posts, i.e. the text/img/table/href code that I want to be applied whenever a post is assigned to this category?
Right now all I have is a trigger if a post is in the 'sell-house-one' category, but nowhere do I have yet what is actually posted when that trigger is called -- my actual fancy designed illustration and call to action.
June 16, 2013 at 5:10 am #46231Brad DaltonParticipantIn the new widget that the code generates.
Its all setup as soon as you grab the code from the view raw link and paste it at the end of your child themes functions.php file using a code editor.
Any existing posts or new posts assigned to that specific category will include the content after the posts which you add to the new widget. Simply paste the HTML for the content into a new text widget and drag it into the new widget area.
Anything else i can help you with?
-
AuthorPosts
- The forum ‘General Discussion’ is closed to new topics and replies.