Customize the cancel_comment_reply_link WordPress - php

As the title suggests, I want to modify or customize the cancel_comment_reply_link without editing the /wp-includes/comment-template.php.
The code in comment-template.php looks like this:
<h3 id="reply-title" class="comment-reply-title">
<?php comment_form_title( $args['title_reply'], $args['title_reply_to'] ); ?>
<small>
<?php cancel_comment_reply_link( $args['cancel_reply_link'] ); ?>
</small>
</h3>
Basically, I want to get the cancel_comment_reply_link out of the <h3> and <small>-Tags into a <div> container but I really don't know how to achieve this without touching comment-template.php.
Is there a solution to include into my theme's functions.php?
Thanks for any help.

I copied the complete comment_form function into my functions.php, renamed it, modified it and included the new function instead of the old one.

Related

Changes to page.php and single.php not applying

I'm having quite a weird issue with my WordPress site. I am building a theme from scratch and I'm trying to make change to the containers on my blog page (page.php and single.php). Weirdly enough, I have made no major changes to the code other than add a wrapper, but the changes aren't showing up.
I've made many themes without this issue so I'm unsure what's going wrong this time. I have set the blog page to be the posts page in the settings so I can't understand why the template won't update. The code I have is below, and is just the standard WordPress code with the exception of 'grid wrapper' and attempting to remove the sidebar which also shows.
I have done quite a bit of research on this to see what the problem could be, but sadly the only post similar was in 2014 with no answer.
<div class="container main-content">
<div class="grid wrapper">
<section class="the-content">
<main>
<h1><?php the_title(); ?></h1>
<?php while ( have_posts() ): the_post(); ?>
<?php get_template_part('template-parts/content', 'page'); ?>
<?php endwhile; // End of the loop. ?>
</main>
</section>
</div>
</div>
Long story short, my content shows just fine. I just can't edit the wrapper which contains that content.
I would change parameters in get_template_part()
This is how it supposed to be used: Understanding get_template_part
So if you have blank Wordpress file structure, I'm not sure if you have template-parts for sure. You can have them only if you intentionally made them.
Use wordpress Wp-Super_cache Plugin
I had the same issue. Most likely index.php is overriding your file as in my case. It depends how your theme handles the loop so check out on your index.php and change it there.
If i remember well, the blog page set in the back-office reference first at home.php and then index.php. Page and single aren't call.

How to replace dynamic_sidebar in PHP?

I'm not a PHP developer and I don't understand the language at all. However, I'm asked to modify a PHP page. It's a WordPress blog. It has a block of code:
<div>
<?php dynamic_sidebar( 'pre-footer-1' ); ?>
</div>
When I load the page, I can see a sidebar added to a footer. I don't want the sidebar. I just want the information comes out fro the index 'pre-footer-1'. How should I modify the code to make it work? I tried:
<div>
<?php echo( 'pre-footer-1' ); ?>
</div>
Sorry, I just don't know how to simply show the content without the dynamic sidebar.
EDITED:
It's a Wordpress theme. The theme has a pre-footer that I can modify in the theme setting. The theme always show a sidebar on a pre-footer. It's not a bug, it's the way how the theme is designed. However, I don't like it and would like to get rid of the sidebar. I still want to show the footer just not the sidebar. I don't know php and would like a simple solution to modify the PHP code such that the sidebar is gone.
Did you try output buffering? Something like:
<?php
ob_start();
dynamic_sidebar('sidebar-id');
$sidebar = ob_get_contents();
ob_end_clean();
?>
This should get you the contents of the sidebar. Just echo the $sidebar where you need it.

How to modify woocommerce_before_cart action

I'm trying to make my woocommerce cart template display as a full 12 column layout.
The existing layout is using bootstrap's col-sm-8 column. I need to change it to col-sm-12.
<main class="main col-sm-8" role="main">
<div class="page-header">
<h1>Cart</h1>
</div>
<div class="woocommerce">...</div>
<div class="woocommerce-info">...</div>
<div class="cart-collaterals">
// shipping code etc.
</div>
</main>
I checked out the relevant woo-templates shown here, and copied the cart.php template into my theme to override. However, it looks like I need to modify the woocommerce_before_cart action to change the <main> layout and insert the col-sm-12 class. I found the relevant actions on this woocommerce page.
I can see from the cart.php template the action called before the <form> element as shown below:
global $woocommerce;
wc_print_notices();
do_action( 'woocommerce_before_cart' ); ?>
<form action="<?php echo esc_url( WC()->cart->get_cart_url() ); ?>" method="post">
<?php do_action( 'woocommerce_before_cart_table' ); ?>
<table class="shop_table cart" cellspacing="0">enter code here
I'm new to php, my question is how do I modify the output of this action so I can change the layout to 12 columns?
Woocommerce inserts the content in cart.php into page.php in the root of your theme. :)
Doesn't look like woocommerce creates action hooks for 'woocommerce_before_cart' or 'woocommerce_before_cart_table', you can check this with has_action(). They seem to be there as suggestions for developers to extend upon. Should be right to remove them from cart.php (although developers might have them there for future releases or popular plugins) or if you want to use them add this to your themes functions.php.
add_action('woocommerce_before_cart', 'sample', 1);
function sample() {
echo '<h1>hello</h1>';
}
EDIT:
Just read your response to the previous answer, looks like that theme you're using might be creating the hook in its functions.php file, look for
add_action('woo_commerce_before_cart', 'sample', X);
'sample' is the name of the function that is called and X is its priority. You can either modify the output of that function or add another function to the hook.
For anyone who works with child theme, please note that sometimes your parent theme already override the cart.php template, especially heavily customised like Themeforest products. So don't copy the original cart.php from Woocommerce, copy it from the parent theme template.

Replace word in template page with title of page in php

I am now starting to realize the infinite ways a person can utilize php.
I have created a template page called new-member.php that calls in the content from another page so that when I add a new member, it is fast and easy.
The path I use now is:
I add a new page with the company name as the title.
I choose the new member template.
I Click publish. This creates a "new member coming soon" page that is up in seconds. Perfect!
But I would like to take it to a higher level and have a php function replace "New Member" with the page title (The company name) so that when I add a new page, not only does it have the new members url, but instead of saying "New Member coming soon" it says "XYZ Company Coming Soon!" which is a temporary page until the official one is built.
Could someone please show me the correct code and where to place that code? I am using wordpress. I have no clue how to write this code. Does the code go into the new member.php template? The header? I have no idea but want to learn!
Please help!
What you need to do there (if I were in your position I would have put together a plugin or do some functions.php hacking) is capture the output of the included page and replace your specific tag "New Member" with what you need. In the below example i'm going to use %NEW_MEMBER_NAME% instead of "New Member", which makes your replacement string more unique, so that in your placeholder wp page you will write
"%NEW_MEMBER_NAME% comig soon".
<?php /* Template Name: New Member */ ?>
<?php get_header(); ?>
<div id="primary">
<div id="content" role="main">
<?php
the_post();
// i don't think you need this anymore
// get_template_part( 'content', 'page' );
?>
<div class="entry-content">
<?php if(function_exists('iinclude_page')) {
ob_start();
iinclude_page(112);
$content = ob_get_clean();
echo str_replace('%NEW_MEMBER_NAME%',the_title('','',false),$content);
} ?>
</div>
</div><!-- #content -->
</div><!-- #primary -->
<?php get_footer(); ?>
Remember that it's never a good ideea to hardcode things in your templates, as you are doing here with "112", the id of your placeholder wp page, and presumably the replacement tag %NEW_MEMBER_NAME%.
You should fork the theme, and create an admin options page for these two.
Hope this hepls you in some way.
Edit your newmember.php template file. Find 'The Loop'. This is where your post content is shown. Echo the title out.
http://codex.wordpress.org/Function_Reference/the_title
//syntax
<?php the_title( $before, $after, $echo ); ?>
//add this to your newmember.php template
<?php the_title('<h3>', '</h3>', true); ?>
If you post what is in your newmember.php template file then a more specific answer can be provided. But this is simple enough, I think you can probably figure it out on your own.
Not sure If I understood your question correct.
But here is what I think you may have to do.
Just replace
New Member coming soon
with
<?php the_title();?> coming soon
Now you will get the page title instead of "New Member".

How to make a page for Custom Post Types in Wordpress 3.0?

I have some custom post types, such as 'review'. I can't seem to find out how to make a section (e.g., www.mysite.com/reviews/) which works like the blog home page, but lists reviews instead of posts (with pagination and everything). I'd like to use a separate template for it too.
Create a page called reviews and then create a new template in your theme folder called page-reviews.php. Add all the necessary elements to the template and include a query_posts in front of your post loop. It should look like this:
<?php query_posts("post_type=reviews"); ?>
<?php if (have_posts()) :?>
<?php while (have_posts()) : the_post(); ?>
<div class="post" >
<h2><a href="<?php the_permalink() ?>" ><?php the_title(); ?></a></h2>
<?php the_content(); ?>
</div><!-- Post ends -->
<?php endwhile; ?>
<?php else: ?>
<p>Sorry, we could not find what you were looking for</p>
<?php endif; wp_reset_query(); ?>
You need help getting .htaccess to convert your categories into hard URLs. I thought WP did this automatically so you'll want to look and make sure you have set up the directory permissions on WP so it can write to your .htaccess file.
Please read this guide and it will be cleared up.
Duplicate the file in your theme called "single.php" and rename it to "single-reviews.php"
Since "single.php" is used for your regular posts, you can append the name of the custom post type to the end of "single-" to automatically use that.
Now once inside of the file "single-reviews.php" you can adjust the layout to be how ever you want.
If you get a 404 error, or it is not showing you the correct layout, you may need to flush the rewrite rules. You can do this two ways.
Go to the permalinks page in your backend and it will sometimes auto flush them.
The best way to do it is in your "functions.php" file in your theme directory add the following code:
add_action ( 'init', 'flush_rewrite_rules' );
function flush_rewrite_rules()
{
global $wp_rewrite;
$wp_rewrite->flush_rules();
}
Create a new page called reviews. Create a new page template that calls the custom post type. Assign the page template to the page...

Categories