Avatar of Marco Gasi
Marco GasiFlag for Spain

asked on 

WordPress best way to embed post content in a static page

Hi everybody.
So I'm building a very basic website for a small client. My client wouldlike to have the option to periodically write a short content to announce a special offer or some other news.
I thought to just use post and one of the many post widgets, displaying only one post, setting the widget to sort posts by date descending and that should be all.
The problem is that these widgets display the post excerpt loosing any formatting of the text: so if my client writes a new post using some bold text, changing the color of a line or something else, all this will be lost when displayed in the home page.

Maybe it be something obvious but I'm still lloking for a solution. I'm using Elementor Pro but coding solutions are good too.

Any idea?
Thank you in advance for any suggestion :)
WordPress

Avatar of undefined
Last Comment
Marco Gasi
Avatar of David Favor
David Favor
Flag of United States of America image

This is a common problem, which has many contributing factors.

Here's how I fix this.

1) Use https://wordpress.org/themes/generatepress for your theme.

Reason: Many themes are broken... in so many different ways... so many variations... the conflict with plugins + WP Core + Gutenberg...

Rather than deal with these complexities, only use a light weight theme.

2) Use https://wordpress.org/plugins/classic-editor to disable the entire Gutenberg editing facility.

Reason: Same as #1. The complexities... at least for now... of Gutenberg + many themes + page builders leading to all manner of content rendering problems is large.

Rather than deal with trying to understand + debug + push back on developers to fix their code, just disable Gutenberg.

Especially for a simple site.

3) Elementor... sigh... Many page builders - Elementor + Beaver especially - use a similar implementation approach... which increases round trip POST data payloads as site complexity increases.

This eventually causes Apache memory overruns + seriously odd errors.

I've opened tickets for years against both page builder to fix this problem.

There are 2x solutions....

a) If you hit this problem, usually using an incognito window fixes the problem.

b) Or better, rather than using a Page Builder, use a show posts plugin.

https://wordpress.org/plugins/search/show+posts lists 100s of these plugins.

https://github.com/search?q=wordpress+show+posts+plugins lists 200+ more of these plugins.
Avatar of David Favor
David Favor
Flag of United States of America image

The other potential problem is if there's a plugin installed which is munging the Text/HTML view + Text/HTML save of posts.

Try this to debug problem...

1) Install the classic editor enabler above.

2) Deactivate all plugins, except classic editor enabler.

3) Now visit your post. Make sure you've selected "Visual" representation. Save post. Publish post.

If problem clears, then likely 1x of your plugins is the problem.

4) Then enable 1x plugin at a time, execute #3 again, rinse + repeat (continue #3) till you identify the problem plugin.
Avatar of Marco Gasi
Marco Gasi
Flag of Spain image

ASKER

Thank you so much David for your response.

But I suspect I've not been clear enough about my issue.

First thigs first, I'm using Astra theme and, I confess, one of its starter templates: As far as I know, Astra is a light enough theme, but I'm not sure about starter templates.

Anyway, what's important to highlight is this: the post itself looks exactly as I expets it looks in its own page: bold text is bold, red text is red and so on (my client will use this to announce some special offer).

But I want to show this post in the home page: so I've used (my last trying) the post block addon provided by Unlimited Elements for Elementor plugin: it looks good enough but it doesn't reflect the formatting rules set in the post: bold text is bold, red text is black... The only rules applied are the ones set through the addon itself. And this happens with any plugin I've tried out.

I might be happy with what I've got because I don't hink my client will spend hours formatting the text of its announcements. But, as usual, I would like to know if there is a way to publish an excerpt of a post respecting the formattin rules set in the post itself.

Thank you.
Avatar of Scott Fell
Scott Fell
Flag of United States of America image

Marco, I think the issue is you are using the Excerpt instead of the post. The excerpt does not have formating.

Create a shortcode https://codex.wordpress.org/Shortcode in your functions.php file that takes the content from a specific post

Then grab the content of a specific post to output to the shortcode
$specials_post = get_post(100);   //ASSUMES THE POST ID IS 100
$specials_content = apply_filters('the_content', $specials->post_content); 

Open in new window


If that is something you want to try, I can refine this for you.
ASKER CERTIFIED SOLUTION
Avatar of Scott Fell
Scott Fell
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of David Favor
David Favor
Flag of United States of America image

1) The Astra theme is fairly lightweight, similar to GeneratePress, so is also a good choice.

Also Astra... plays nice with Elementor, where other themes... play poorly with Elementor...

2) But I want to show this post in the home page: so I've used (my last trying) the post block addon provided by Unlimited Elements for Elementor plugin: it looks good enough but it doesn't reflect the formatting rules set in the post: bold text is bold, red text is black... The only rules applied are the ones set through the addon itself. And this happens with any plugin I've tried out.

This seems... odd...

Likely someone will have to log into this site to debug this.

3) I might be happy with what I've got because I don't think my client will spend hours formatting the text of its announcements. But, as usual, I would like to know if there is a way to publish an excerpt of a post respecting the formatting rules set in the post itself.

A good reason why this sort of work is always best billed by the hour, with a paid-up-front retainer.

This way a client can ruminate for hours about font point size or some other... formatting element... while you keep your bill rate at an acceptable level.
Avatar of Marco Gasi
Marco Gasi
Flag of Spain image

ASKER

Sorry guys, I've been busy...
@Scott, that seems to be interesting, I'll check if it work as I expect (and if I'm able to do it :)) and I'll come back to you
@David you're right but if I'd try to get paid by hour here in Canary Island I'd just lose clients :D  Or simply i'm not a good commercial...

Thank you both for your advices. Come back to you soon.
Avatar of Marco Gasi
Marco Gasi
Flag of Spain image

ASKER

@Scott your code works fine. I've just changed it a bit to get the latest post:

// [specials]
function specials_func( $atts ) {
   $recent_posts = wp_get_recent_posts( array( 'numberposts' => '1' ) );
   $thePostID = $recent_posts[0]['ID'];
   $specials_post = get_post($thePostID);   //ASSUMES THE POST ID IS 1
   $specials_content = apply_filters('the_content', $specials_post->post_content);
   
   //print_r($specials_post);


   return $specials_content;
}
add_shortcode( 'specials', 'specials_func' );

Open in new window

But I have noticed it doesn't get the featured image. No problem: I've dropped the feature image and put the image directly in the post content, centering it. And now in the post the image is centered but in the home page it is aligned to the left. But adding a line of custom CSS solved the issue.

So this is the solution I was looking for. Thank you both for helping.
Cheers
Avatar of Scott Fell
Scott Fell
Flag of United States of America image

I think to get the featured image you can use  get_the_post_thumbnail_url

https://developer.wordpress.org/reference/functions/get_the_post_thumbnail_url/
Avatar of Marco Gasi
Marco Gasi
Flag of Spain image

ASKER

Oh, I'll give it a try just for learning purposes: I think it will be easier for my client to put any images directly in the body of posts.
Thank you for the additional help, Scott. :)
I have a different perspective on Classic vs Gutenberg.

"Gutenberg" is now only a beta testing plugin for WordPress devs to try out latest features. WordPress now ships with "Block Editor", which at this point in time is INCREDIBLE. A lot of work has been done since November 2018 when it debuted with WP 5.0. It was woefully awkward and profoundly frustrating to work with. Now, it's the bomb!

Also, for fans of GeneratePress, GenerateBlocks is fantastic, you can build an entire site out of 'em. And if you go pro, there are endless block templates. It's amazing what you can do with the 4 blocks they provide. So many cool options. Who needs a page builder. Seriously, people are crafting beautiful sites with the Block Editor alone, so there is no need to play nicely with a page builder.

Also, WP devs are working on full page editing which should hit our admins by the end of the year. Sticking with Classic editor will put you out of sync with the innovations happening with WordPress. I stuck it out with Gutenberg and I'm so glad I did! 
Avatar of Marco Gasi
Marco Gasi
Flag of Spain image

ASKER

@Alicia, thanks for posting.
I confess I have tried to use the Block Editor (with Astra theme) and I have built a decent web page. But I found difficult enough manage things like aligning, padding, margins without write some custom css. Things that are terribly easy in Elementor become tricky with the Block Editor.
Maybe I have to learn how to use it better or maybe it can be improved in the future (I heard about some new features and options), but I'm not enthusiastic yet with it.
Can you suggest some learning resource?
Avatar of David Favor
David Favor
Flag of United States of America image

You mentioned, "paid by hour here in Canary Island"...

I live in Austin, Texas... Best I can tell... I currently only have 1x client in Austin.

Tip: If you have Internet Connectivity (you're reading this comment)... might be a great time to consider expanding your client base + income.

If I only had local clients... I'd be living... under a bridge... in a box... with a cat on a leash... with an unhappy wife... :-)
Avatar of Marco Gasi
Marco Gasi
Flag of Spain image

ASKER

If I only had local clients... I'd be living... under a bridge... in a box... with a cat on a leash... with an unhappy wife... :-) 
Exactly like me, David... LOL

WordPress
WordPress

WordPress is a free and open-source content management system (CMS) based on PHP and MySQL for creating websites and blogs. Features include a plugin architecture, a template system and strong management, customization and search systems; through its dynamic presentation of content, webmasters have the flexibility to create websites easily.

11K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo