Wordpress manipulate comment_reply_link() add #nav-comform to the link - wordpress

I am working on a theme for a friend but get stuck ...
The comments and the comment form are inside a jquery tab.
To toggle the tab on a klick of the reply link i have to add #nav-comform to the link.
Example:
http://localhost/?p=109&replytocom=10#respond#nav-comform
I know i have to work with a filter in the functions.php but i have never done it before so i am a little lost and everything i try fail ...
I know it should be something like this filter example to add rel="nofollow" to the reply link:
function add_nofollow_to_reply_link( $link ) {
return str_replace( '")\'>', '")\' rel=\'nofollow\'>', $link );
}
add_filter( 'comment_reply_link', 'add_nofollow_to_reply_link' );
Maybe some one can lead me a way ?
Thank you very much !!

Try the following
function add_link_hash($args){
$args['respond_id'] = 'nav-comform';
return $args;
}
add_filter('comment_reply_link_args', 'add_link_hash', 10);

Related

Wocommerce back button from single product back to previous page styling to make it a button

I've made a back link to take customer from single product back to product display. I need to know how to give this code a class to make it a button.
The code is
add_action( 'woocommerce_after_add_to_cart_button', 'back_button', 10 );
function back_button() {
global $product;
echo ' Go Back to selection ';
Thanks
I tried putting
add_action( 'woocommerce_after_add_to_cart_button', 'back_button', 10 );
function back_button() {
global $product;
echo ' <button>Go Back to selection</button> ';
}
In answer to my own question, even though it's not really what I was after but it does the job. I got Wordpress Back button widget plugin. It lets you add “Back” button to your website.
The button can be added via widget, [alg_back_button] shortcode or echo alg_back_button( 'Back' ); function. So until I learn more, this will do. I hope this will help someone else :)

Where exactly is the "Before Header Content hook" in Wordpress?

I want to add a little code to the "Before Header Content hook" but I don't know where that is... Can you please help me?
Try:
add_action('init', 'process_post');
function process_post()
{
echo "test";
}
this is a modified version of #ajay 's solution
if you are going to use this, then you have to make sure that the current user is not an admin using is_admin() function.. and only display it if he is not an admin ...
why !?
because if you didn't, it may mess up the wp-admin of your website..
add_action('init', 'process_post');
function process_post()
{
if (!is_admin()) {
echo "test";
}
}
This could be tricky simply because every theme differs with how the loop is displayed, however you could create a plugin to use the loop_start action, which is called before the first post of the standard WP loop:
add_action( 'loop_start', 'test_loop_start' );
function test_loop_start( $query ){
echo 'this is my inserted text';
}
Now using this would display it every single time the loop is called (whether on a page, a post, category page, search page, etc.), which you may not want.
add_action( 'loop_start', 'test_loop_start' );
function test_loop_start( $query ){
if(is_category() OR is_singular()) {
echo 'this is my inserted text';
}
}

Remove header (first row) from csv export

The company I work for has bought the amazing plugin "WooCommerce Customer/Order CSV Export" which really works like a charm. The documentation is sublime, I got my extra fields and I get the snippets to customize my export, this all works perfectly!
Now, I have a small problem with the headers. I need to remove them and I found a filter to apply but I don't understand how to make a function out of this. Can you maybe provide me a way to export the data without the headers on the first row?
So basicly, can you help me write a function that removes the first row of the export or hide the header array?
This is the filter I found in the documentation:
apply_filters( 'wc_customer_order_csv_export_generated_csv', $csv, $this );
Many thanks in advance and with kind regards,
Try this:
//delete headers
function delete_headers_csv($csv){
foreach (explode("\n", $csv) as $line) {
if ($i != 0 ) {
$temp .= $line."\n";
}
$i++;
}
echo $temp;
}
add_filter( 'wc_customer_order_csv_export_generated_csv','delete_headers_csv');

WooCommerce Registration Shortcode - Error messages problems

I am currently creating a widget to display the registration form on a WordPress website that uses WooCommerce. For now, I only have 3 basic fields which are email, password, repeat password. I'm looking forward to add more WooCommerce fields, but want to solve that problem before jumping to the next step.
I'm having some problems with the messages output (wrong password, account already exists, etc).
I searched on the web and there was no shortcode already built for WooCommerce registration, beside their registration page. So I went ahead and created a shortcode, with a template part.
function custom_register_shortcode( $atts, $content ){
global $woocommerce;
$form = load_template_part('framework/views/register-form');
return $form;
}
add_shortcode( 'register', 'custom_register_shortcode' );
This is a snippet I use to get the template part inside a variable, since the default function would "echo" the content instead of "returning" it.
function load_template_part($template_name, $part_name=null) {
ob_start();
get_template_part($template_name, $part_name);
$var = ob_get_contents();
ob_end_clean();
return $var;
}
So, the problem is, when I call woocommerce_show_messages or $woocommerce->show_messages(); from my template part, nothing is showing, or if it is, it shows at the top of the page.
I did try to put the calls inside my shortcode function:
function custom_register_shortcode( $atts, $content ){
global $woocommerce;
$woocommerce->show_messages();
$form = load_template_part('framework/views/register-form');
return $form;
}
add_shortcode( 'register', 'custom_register_shortcode' );
Doing so, the message output inside the <head> tag, which is not what I want.
I tried to do the same trick with ob_start(), ob_get_contents() and ob_clean() but nothing would show. The variable would be empty.
I also did try to hook the woocommerce_show_messages to an action as saw in the core:
add_action( 'woocommerce_before_shop_loop', 'woocommerce_show_messages', 10 );
For something like:
add_action( 'before_registration_form', 'woocommerce_show_messages');
And I added this in my template-part:
<?php do_action('before_registration_form'); ?>
But I still can't manage to get the error messages show inside the box. It would always be inserted in the <head>
I will share final solution when everything is done.
Thanks for your time,
Julien
I finally got this working by hooking a custom function to an action which is called in my header.php
I guess hooking functions inside template part does not work as intended.
In header.php, I got this:
do_action('theme_after_header');
And here's the hooked function. Works perfectly.
function theme_show_messages(){
woocommerce_show_messages();
}
add_action('theme_after_header', 'theme_show_messages');
However, I will look into 'unhooking' the original show message function since it might show twice. Need to test some more ;)
You can also just use the [woocommerce_messages] shortcode in your template where you want it displayed
Replying to a bit of an old question, but you can also try the following:
$message = apply_filters( 'woocommerce_my_account_message', '' );
if ( ! empty( $message ) ) {
wc_add_notice( $message );
}

Wordpress remove shortcode from content

Is it possible to remove the gallery shortcode from the content before when the_content() is executed? I searched codex and found remove_shortcode( $tag ) but they show no examples.
I tried adding to functions
function remove_gallery($content) {
$content .= remove_shortcode('[gallery]');
return $content;
}
add_filter( 'the_content', 'remove_gallery', 6);
It doesnt work..
Update:
I was able to unregister the shortcode using the code below, but it also removes the content
function remove_gallery($content) {
return remove_shortcode('gallery', $content);
}
add_filter( 'the_content', 'remove_gallery', 6);
I know this is a relative old question, but the strip_shortcodes function does work!
global $post;
echo strip_shortcodes($post->post_content);
Easiest way if you ask me..
Strange. remove_shortcode (codex link) doesn't take a second argument.
You're returning either the true or false return of the remove_shortcode function, not the content with the shortcode removed.
Try either something like this in that second version of your function up there:
remove_shortcode('gallery');
return $content;
Or just put
remove_shortcode('gallery');
In your functions.php file. The previous poster suggested including the [ ]'s, which I guess is wrong.
I think you should use sub string replacement like this:
function remove_gallery($content) {
return str_replace('[gallery]', '', $content);
}
add_filter( 'the_content', 'remove_gallery', 6);
Bear in mind, this method does not come with good performance.
update: You can unregister the shotcode in function.php by adding code:
remove_shortcode('[gallery]');
An old question, but after some digging and a combination of answers this worked for me:
<?php $content = get_the_content();
echo strip_shortcodes($content);?>
I was only inserting galleries, which I wanted to remove and display separately. Obviously if you want to remove a specific shortcode this might not be the solution for you.

Resources