The idea behind this question lies in getting excerpt of the posts created with avada but I can't strip the shortcodes from the post content to display the excerpt of the post.
Here is example of my post (using avada):
[fullwidth background_color="" background_image="" class="" id=""]
[one_full last="yes" spacing="yes" class="" id=""][fusion_text]
Content text ...
[/fusion_text][/one_full][/fullwidth]`
The default the_excerpt(); doesn't work because of shortcodes. get_content() returns the full post content including shortcodes. Using strip_shortcodes() also removes the content between the shortcodes.
So my plan would be to strip shortcodes using pattern? and trim the message to mimic the excerpt functionality.
PS: This pattern doesn't work.
Use this regex:
$excerpt = get_the_excerpt();
$excerpt = preg_replace("~(?:\[/?)[^/\]]+/?\]~s", '', $excerpt);
It's worth commenting that you can do this same thing using a text editor, for instance Notepad++ or EditPad Pro, using this Regex: \[/?[^/\]]+/?\]
That will match all shortcode, and you can then replace with nothing or a space, whatever.
Related
I write a text in Wordpress text editor as in image, with line breaks and everything
Only in my code if I put it this way
$post->post_content
On my site page it does not break the line the way I put it in the text editor
And if I put it this way in the code it breaks the lines and respects the same formatting of line breaks that I put in the text editor
<?php while(have_posts()): the_post();
the_content()
?>
How can I solve this problem?
If you're using the_content(), WordPress runs the post's content through a series of filters (the filter name is also the_content). One of them is wpautop that replaces blank lines with <p>...</p> tags.
You can either do that part yourself, or run all the filters outside the loop by using
echo apply_filters("the_content", $post->post_content);
$post->post_content returns raw data. While if the quicktag is used in a post to designate the “cut-off” point for the post to be excerpted, the_content() tag will only show the excerpt up to the quicktag point on non-single/non-permalink post pages. By design, the_content() tag includes a parameter for formatting the content and look, which creates a link to “continue reading” the full post.
apply_filters('the_content', $content); is meant to be used to apply formatting to raw post content.
Too get the same effect:
<?php
$content = apply_filters('the_content', $post->post_content);
echo $content;
?>
Reference: https://developer.wordpress.org/reference/functions/the_content/
I want to display the content of a specific page using the theme files.
I tried this :
$import_page = get_page_by_title(page-title-here);
echo "$import_page->post_content";
It works except that it doesnt display the formatting of the page. only text and the images, It avoids the line breaks, paragraph formatting ect.
Thank you for helping me to get this sorted.
You need to apply the_content filter to post_content before printing it.
Like so
echo apply_filters('the_content', $import_page->post_content);
You can find out more about the_content filter.
http://www.mytwins.gr/site/
In the third blog post you will see that a shortcode shows up [frame align="none"]Της Εύης Σταθάτου[/frame] which is ugly. Only if you click it, it works fine.
Why is that?, How can you hide the code from the previews posts thingy? Thanks in advance.
P.S I tried to hide the shortcode from the visual mode and enter it in the text mode, but still the same.
As #Ravi suggests, make sure that your plugins are enabled. However, it looks like your shortcodes are appearing within your excerpts (assuming you're using the_excerpt() for the snippets appearing on your homepage?)
I would suggest a handy snippet of RegEx:
$myExcerpt = get_the_excerpt();
$myExcerpt = preg_replace( '|\[(.+?)\](.+?\[/\\1\])?|s', '', $myExcerpt);
echo $myExcerpt;
That should stop the raw shortcodes from appearing.
On a mobile version of my site, I want to ignore the tag and display the full text of every post. How can I do this? This cuts off the text and inserts (more...):
<?php the_content(); ?>
In your PAGE.PHP underneath this code you are using EXCERPT function, either remove EXCERPT from there.
I would like to display the posts the way they are shown when you have "show latest post" selected under reading settings.
I've tried using query_posts, but that displays the whole post, not the chunk that appears in the preview with the link at the bottom.
any ideas what I should be querying to get that?
Edit
I forgot to mention
I tried using the_excerpt(), but that doesn't show the image in the post. Also the index.php file is using the the_content() and it's displaying it the way I want it to
If you don't want to show the whole post, you should use the_excerpt() instead of the_post()
Edit:
From codex:
<?php the_content('Read more...'); ?> Displays the content of the post and uses "Read more..." for the more link text when the Quicktag is used.
Basically, use the_content('your text for the link') and add the quicktag to your article, this will automatically just show the text before