Replacing Wordpress comment_form - php

I'm trying to replace the comment_form with custom built solution. But I cannot seem to figure out how to do this and the code is lacking:
http://codex.wordpress.org/Function_Reference/comment_form
Ideally, anytime that the comment_form function is called, I want to replace it with an iframe to another site. Is there a way of doing this?

there is no way you can overwrite comment_form() function,
if you want to overwrite comment_form then its not possible in right way.
instead you can you use filter like comment_form_before and comment_form_after to achieve what you want.
i am putting this answers because i just see code of comment_form()
something like
<?php add_action('comment_form_before',function(){
echo '<div style="display:none;">';
});
add_action('comment_form_after',function(){
echo '</div><iframe><iframe>';
});
?>

Related

Changing woo commerce HTML that gets outputted with do_action

I'm trying to build a webshop with woo commerce which seems like a very nice and easy to use system. But I'm really having some trouble with it. A lot of times there's a function like this in the code: do_action( 'woocommerce_checkout_order_review' ) which outputs some HTML that I really want to change. The documentation that is provided isn't making me any wiser. How can I change this HTML. I would really appreciate any help trying to understand how this works!
The answer to the question, how do I modify the content ouputted in woocommerce_checkout_order_review ?
The answer:
The HTML is located in the template file here:
wp-content/plugins/woocommerce/templates/checkout/review-order.php
You can easily modify this content in a plugin or theme. Read more about that here: http://docs.woothemes.com/document/template-structure/
do_action( 'woocommerce_checkout_order_review' )
this is action declared somewhere, this is done so that whenever you want to add anything for example say "hello there", you dont have to hardcode it .. you can simply do it this way ..
function add_something() {
echo 'hello there';
}
add_action('woocommerce_checkout_order_review','add_something');
Refer here
Add Action
This would add "hello there" in the rendered html page..exactly where you have do_action('woocommerce_checkout_order_review'); in the code . keep this snippet in your functions.php and play with it ;)

Add paragraph tags to post content in wordpress?

I'm getting some pages with the get_pages function and echoing the page content like: $page->post_content, but contrary to the_content(), this way wordpress wont add p tags automatically, is there any way to add them here?
Thanks in advance
You should use <?php echo apply_filters('the_content', $page->post_content); ?>
Use the wpautop() function.
Jose Carlos' answer is actually the better approach. Out of the box, 'the_content' filter is loaded with the following actions:
capital_P_dangit
wptexturize
convert_smilies
convert_chars
wpautop
shortcode_unautop
prepend_attachment
So you can see that there's a lot more intelligence behind this filter. If you're positive that you don't need the other stuff (are you 100% sure you'll never have shortcode or smilies in your text?) then go ahead and use wpautop(), but you may regret it later on.
This might be what you're looking for, isn't it?
<?php
// Get WordPress pages
$wp_pages = get_pages();
foreach ($wp_pages as $wp_page)
{
echo '<p>';
echo $wp_page->post_content;
echo '</p>';
}

do_shortcode not working

I've been stuck on this for a while. I'm working on a wordpress site where I wrote the theme from scratch, I use php calls to get the wordpress functionality that I need in certain sections.
I'm trying to use a plugin, but calling it via
echo do_shortcode('[STORE-LOCATOR]');
just isnt working. Even when I switch to the default template and post that code, it still doesnt work. It simply echoes "[STORE-LOCATOR]"
Any help would be greatly appreciated.
[STORE-LOCATOR] is probably not a 'shortcode' in WordPress sense.
I encountered this on different plugin, Stream media player. They use the same syntax as shortcodes, but they are actually not.
Try using:
echo apply_filters( 'the_content',' [STORE-LOCATOR] ');
instead of do_shortcode, and see if it helps.
do_shortcode() returns a string.
I get it working by doing:
<?php echo do_shortcode(...); ?>
This is specific to the Store Locator plugin, not do_shortcode in general.
apply_filters can be an acceptable workaround for other plugins, but this does not work for Store Locator; you will only see an empty space and some controls. This is because it is looking for that shortcode in the page/post body to determine whether or not to include all of its js references at the top of the page. And without these references, nothing will work. See the sl_head_scripts function in sl-functions.php.
To change this behavior, simply modify that function to match based upon page title instead. In my instance I wanted it only on a "shop" page, so I commented out the entire $on_sl_page test and replaced it with this:
$on_sl_page = ( strpos($pagename, 'shop') === 0 );
I then called it from my page with apply_filters as indicated in the other answer:
echo apply_filters( 'the_content','[STORE-LOCATOR]');
And this appears to work perfectly.
echo do_shortcode('[STORE-LOCATOR][/STORE-LOCATOR]');
Try using shortcode after the WordPress environment has been set up.
function my_function() {
echo do_shortcode('[STORE-LOCATOR]');
}
add_action('wp', 'my_function');
If you're writing the whole thing from scratch, you'll want to make sure that the function you create is in the root php file of your plugin. The function might look something like this, but you'll have to sub in whatever logic you're using to arrive at the store location:
<?php
function doCoolStuff () {
$var1 = "value1";
$var2 = "value2";
$output = $var1+$var2;
}
return $output;
}
add_shortcode('SOTRE-LOCATIOR', 'doCoolStuff');
?>
Then in your template put the code:
<?php echo do_shortcode('[STORE-LOCATOR]');?>
Happy coding and good luck!

Wordpress 3 - Remove Links from Posts via functions.php

Is there a way that I can remove links in posts via my functions.php file. Basically I don't want anyone to be able to go outside of the blog posts that are viewed. I have hundreds of posts so I obviously can't go through all of them and remove them manually. Or could I use javascript?
Thanks so much.
Updated: The jQuery below is great. Does anyone know if there is a way I can do it thru php in my functions.php file? If, for whatever ridiculous reason, someone has JS disabled is why I ask.
Thanks!
You could use JavaScript, but you're not going to be able to stop people leaving if they want to.
Something like this may work, although I haven't tested and it was written off-hand:
<script>
$('#content a').each(function() {
$(this).replaceWith($(this).text());
});
</script>
With the jQuery library, this should replace all <a> tags with what was in between them.
So Google should become just Google.
You can strip out the links on the fly using a regular expression -
$post_content = get_the_content();
$post_content = preg_replace( "|<a *href=\"(.*)\">(.*)</a>|", "\\2", $post_content );
echo $post_content
This would need to go in your theme wherever you print the_content. Untested.

putting a php code into another php code! Possible?

i'm a wordpress user and i have a php code, and in that php code there is an area to put a url in: $url = "http://blabla.com"; well in wordpress you can call post permalinks with this code: <?php the_permalink(); ?> What i want to do is putting <?php the_permalink(); ?> instead of http://blabla.com above in the php code. Target is: getting permalinks put them there in php code, and let the php code use them to do its job. Is that possible? If yes, how with an example please...Thank you...
You could assign the return value of get_permalink() to $url:
<?php $url = get_permalink(); ?>
get_permalink() is different from the_permalink() because it doesn't display the link, but just returns it. (Originally this answer naively used the_permalink(), but I did some extra research to be sure.)
The above answer will not work. Use get_permalink().
the_permalink will display it's output
get_permalink will return the value.
<?php $url = get_permalink(); ?>
You need to understand the concept of some Template Tags, since the_permalink fits this category. They are defined especially for use in WordPress Themes. They can be summarize as "a code that instructs WordPress to "do" or "get" something".
Writing the_permalink simply echoes the permalink in your template. It's not something that you get in a php function and manipulates it. It just echoes the html of the information it needs to show.
This is useful for designers working out template files in Wordpress themes: they don't need to understand a lot of programming or a lot of php keywords: they just need to know that writing "the_permalink" gives them the desired html output.
What you're trying to do is get the output from a template tag that already outputs it's value. You need to use other template tag that RETURNS the value you want to use instead of ones that OUTPUTs it.
In your example, you need the get_permalink. Since the_permalink is used in the Loop, you need to provide a post id to your get_permalink function.
There are another examples that fits the same problem domain: for example, I can't manipulate what wp_list_pages returns (because it automatically outputs it's result), so I need get_pages (that RETURNS an array) to manipulate it's result.
Read Wordpress official documentation at Codex. It's great.

Categories