I have a word document, with all my posts already write on it.
So I just have to copy/paste all these posts on my tinyMCE advanced Editor in my Wordpress 4.1
The only problem is that it doesn't take care about line break when I echo them in my blog page.. Whereas I can see these line break on tinyMCE visual preview. And if I check in the tinyMCE text mode, I don't see any <br /> or any <p> tags.
Does anyone had this problem ?
I have created my own template. And it is my first time on Wordpress so I could have miss something, but everyone seems to have a problem with remove_filter ('the_content', 'wpautop'); in their function.php But I don't have this function and I try with add_filter ('the_content', 'wpautop'); but it doesn't change anything.
Thank you in advance!
In your themes template where you output the_content try this:
$getPost = get_the_content();
$postformatted = wpautop( $getPost );
echo $postformatted;
You may want to remove the filter you added if it does not initially work.
Related
I need to write pure PHP codes in WP posts - not using a plugin or snippets etc.
I know this Q has been asked before, but all were answered by using plugins etc.
There were some plugins like PHP-Exec that could do the job, but due to latest WP/PHP updates they no longer work.
Is there any way to write some functions in FUNCTIONS.PHP to allow this?
So a code like this can work as a WP post?
<p>
My text paragraph.
</p>
<?php
// Custom PHP codes - vary in wp posts
echo "Anything ... ";
?>
<p>
My second text paragraphs.
</p>
Thanks a lot guys!
Best approach would be to wrap your PHP code in a shortcode inside functions.php and then call it out of your page.
function anything_function() {
// your actual functionality.
$message = "Anything ... ";
return $message;
}
// register shortcode
add_shortcode('anything', 'anything_function');
And then you can use the [anything] shortcode inside your templates.
Please refer to Shortcode API for more information.
I've tried using remove_filter('pre_user_description', 'wp_filter_kses'); in my functions.php file to allow HTML tags in the author bios but it's not working. The HTML tags are converted to ansii < and > so it just outputs to the screen as raw html instead of rendering it. Any idea why this wouldn't work? I've tried putting this in my child theme functions.php, the parent theme functions.php as well as in a Snippets plugin with no luck. Any help is greatly appreciated!
I figured it out. The issue was in my page template. The output for the author description was this echo esc_html( $author->description ); which nullified my efforts to not escape the html. I moved the template file to my child theme and removed the esc_html() part so it's just echo $author->description; and now everything works great. Sorry to bother everyone, but glad I found the answer!
I'm currently learning wordpress theme development and for better understanding I have downloaded couple of wordpress theme and seeing their code.
But a line of code I can't understand. here it is-->
<?php echo do_shortcode(sq_option( 'footer_text ' ' ')); ?>
maybe its for footer but how this works and how i can use this function when I will create my own.
do_shortcode is a function you have to use if you want to execute a shortcode inside a custom theme template page see more info on the function here: https://developer.wordpress.org/reference/functions/do_shortcode/
Generally do_shortcode(); is use to get data from shortcode or its attribute to your PHP code or to filter any shortcode returning data. Shortcode can be provided by any plugin.
Not sure about it but in your theme's code sq_option("footer_text"); could be a function which is filtering some text from footer.
The code could be as:
<?php echo do_shortcode( '[contact-form-7 id="91" title="quote"]' ); ?>
Reference Link
do_shortcode () is usefull function-> for excute shortcode in template file
I wanted to add shortcode from the text editor of wordpress post.I have added following short code in the post of wordpress:
<img alt="" src="[template_url]/images/ic_sol_1a.png" />
Here [template_url] is the shortcode i wanted to use it was not working. when i see it in the post page it render the text not the short code response. Somewhere i saw a solutions like adding following line to functions.php of theme:
add_filter( 'widget_text', 'shortcode_unautop');
add_filter( 'widget_text', 'do_shortcode');
But still after adding these lines i am unable to make shortcode work. What could be the possible reason?
my shortcode function is like this:
function my_template_url() {
return get_bloginfo('template_url');
}
add_shortcode("template_url", "my_template_url");
You will need to use the get_bloginfo() to return the value as in your example and make sure to use the_content() to print the value to the page. If you use one of the API methods such as get_the_content() then the do_shortcode filter is not run. If you want to apply it use the following:
function my_template_url() {
// This will echo the 'template_url'
return get_bloginfo('template_url');
}
add_shortcode("template_url", "my_template_url");
$shortcoded = apply_filters( 'the_content', get_the_content() );
You do not need the add_filter() lines.
After lots of headache and with the help of #doublesharp and #Nathan Dawson comments/answers we figured out Problem was inside single.php file of theme we were getting the content of post using get_the_content function. By changing it to the_content() function sortcodes start working. Please note that shortcode will not work in the visual editor of WordPress post on admin site but when you see the post actually in the browser by going to that post you can see it working.
In a WordPress woocommerce template, this line outputs woocomerce product description / excerpt
<?php echo apply_filters( 'woocommerce_short_description', $post->post_excerpt ) ?>
Adding my HTML after that line outputs my HTML outside the div that holds the excerpt/description of the product. I am trying to add a div inside the content as if it was added in the editor.
Basically, I want to add something in all products but because I have many products already, I want a way to insert it in template file or something just once and applied to all.
Anyone know how can I do that?
You could add a filter that adds the div, before the woocommerce software adds it. Try something like this, inside your <theme>/functions.php file:
function add_my_div($desc) {
return '<div class="my-div">'.$desc.'</div>';
}
add_filter('woocommerce_short_description', 'add_my_div', 0, 1);
Notice it is on priority 0. This should run before most other filters. The default value for priority is 10, and I am pretty sure that is the priority that WC adds it's wrapper div.
Hope this helps.
jquery .append did the trick for me
http://api.jquery.com/append/
#loushou Thanks for your comment. It looks like your suggestion could work also but I haven/t tried it yet. Will do If I got the time and update my findings here.
Thanks