In this page every link has rel="nofollow".
can you guys please tell me how to remove the nofollow from that page.
I am using WordPress them.
Hoping to receive some help from your side
Thanks in advance
To remove nofollow from link please add the below code in your current active theme functions.php file.
The rss hook not allow to change content within tag, so create custom template for your feed.
/**
* Deal with the custom RSS templates.
*/
function my_custom_rss() {
if ( 'photos' === get_query_var( 'post_type' ) ) {
get_template_part( 'feed', 'photos' );
} else {
get_template_part( 'feed', 'rss2' );
}
}
remove_all_actions( 'do_feed_rss2' );
add_action( 'do_feed_rss2', 'my_custom_rss', 10, 1 );
For more help see this link : Click here.
You can get the content of custom feed templates from core wordpress folder /wp-includes/feed-rss2.php
I hope it will help you.
Take a look at the following code snippet:
global $post;
?>
<?php if ($post->ID == $pageid): ?>
<script type="text/javascript">
$("a").each(function() {
if ($(this).attr("rel")) {
$(this).removeAttr("rel");
}
});
</script>
<?php endif; ?>
Related
I'm trying to insert a button to show at the end of each post on Wordpress in which the link it goes to is defined by a setup using the custom fields plugin. When creating each post, I am able to select the link I wish to display.
Here is the code I have which I know is wrong but I was hoping someone could help here.
function wpb_after_post_content($content){
if (is_single()) {
$content .= 'Contact Franchise →';
}
return $content;
}
add_filter( "the_content", "wpb_after_post_content" );
I assume $franchise_profile_url is a variable and you should concatenate it in the string like this
$content .= 'Contact Franchise →';
function afterContent($content) {
if(!is_feed() && !is_home()) {
$content.= "<div class='footNote'>";
$content.= "<h4>Click the below button if you like it:</h4>";
$content.= "<p><a href='#'>LIKE</a></p>";
$content.= "</div>";
}
return $content;
}
add_filter ('the_content', 'afterContent');
Use the above function. It will help you to achieve what you need.
Thanks for the help here, however, that code simply links back to the post itself and isn't pulling in the URL as set on the post using custom fields. This is the code I had set up before which was working on a default post setup but now I wish to use an alternative method in the functions.php file
<?php if( get_field('franchise_profile_url') ): ?>
Contact Franchise →
<?php endif; ?>
I want to edit this link via wordpress
http://domain-name.com/self-coaching-tips/media/
when I click on edit, I am able to edit the MEDIA part only. I want to update the whole link to
http://domain-name.com/media/
How can I do this?
Add to your functions.php file:
function cstm_url_redirects() {
$redirect_rules = array(
array('old'=>'/self-coaching-tips/media/','new'=>'/media/'),
//array('old'=>'/some-other-old/page/','new'=>'/some/new/page/'),
);
foreach( $redirect_rules as $rule ) :
// if URL of request matches with the one from the array, then redirect
if( urldecode($_SERVER['REQUEST_URI']) == $rule['old'] ) :
wp_redirect( site_url( $rule['new']) , 301 );
exit();
endif;
endforeach;
}
add_action('template_redirect', 'cstm_url_redirects');
More examples here
I have a woocommerce store and want to show wocommerce error messages in specific place of my theme, for example under submit button.
I know wocommerce error messages come from here:
<ul class="woocommerce-error">
<?php foreach ( $messages as $message ) : ?>
<li><?php echo wp_kses_post( $message ); ?></li>
<?php endforeach; ?>
</ul>
But, when i put this code in my page (for example edit-my-address.php page), its giving error!
What is working or simple code for showing messages in woocommerce?
Thanks in advance.
you can use both methods here..
woocommerce_show_messages();
wc_print_notices();
You can also show woocommerce custom notices according to your condition like...
wc_add_notice( 'This is a Success notice', 'success' );
wc_add_notice( 'This is a Error notice', 'error' );
wc_add_notice( 'This is a \'Notice\' notice\'', 'notice' );
You can add this piece of code to functions.php of your child theme
add_shortcode('woocommerce_notices', function($attrs) {
if (wc_notice_count() > 0) {
?>
<div class="woocommerce-notices-shortcode woocommerce">
<?php wc_print_notices(); ?>
</div>
<?php
}
});
And then use it as a shortcode [woocommerce_notices] in any desired post or page, or use <?php echo do_shortcode('[name_of_shortcode]'); ?> in a desired PHP template.
Tested and works. Good luck.
A bit late to the party but here is a solution.
Try to use the following piece of code (taken from the original file here: wp-content/plugins/woocommerce/templates/single-product.php)
<?php
/**
* woocommerce_before_main_content hook.
*
* #hooked woocommerce_output_content_wrapper - 10 (outputs opening divs for the content)
* #hooked woocommerce_breadcrumb - 20
*/
do_action( 'woocommerce_before_main_content' );
?>
Hope it helps
you missed to add this line of code:
<?php wc_print_notices(); ?>
Add this to your functions.php file inside your child theme (or main theme if there is no child).
add_shortcode('woocommerce_notices', function($attrs) {
if (function_exists('wc_notice_count') && wc_notice_count() > 0) {
?>
<div class="woocommerce-notices-shortcode">
<?php wc_print_notices(); ?>
</div>
<script>
(function($) {
$(window).on("load", function(){
// You can execute some js here
});
})(jQuery);
</script>
<?php
// You can execute some php here
wc_clear_notices();
}
});
Then add a shortcode to your page as:
[woocommerce_notices]
The notices and the code will get executed wherever you paste the shortcode.
I'm trying to customize WooCommerce external product links to open in new tabs...
This is my try:
added a filter to the WordPress theme functions.php file as the following:
add_filter( 'woocommerce_product_add_to_cart_url', 'woocommerce_externalProducts_openInNewTab' );
function woocommerce_externalProducts_openInNewTab($product_url) {
global $product;
if ( $product->is_type('external') ) {
$product_url = $product->get_product_url() . '"target="_blank""';
}
return $product_url;
}
What did I missed?
what you're currently doing is wrong... get_product_url is named as what it do. It will give you the url... not the html anchor that has the url, but just the url.. so you're just adding some text to the url.. that's what you are doing...
One solution is given by #Ash Patel. You can change the markup by using templates... just navigate to your plugin folder and look for this file.. woocommerce\templates\single-product\add-to-cart\external.php. You can find instructions inside it.
Now, sometimes, we don't like editing templates... especially if it's just minor edits like this...
Below code will do it the way you want it... just paste this code in your theme's functions.php.
remove_action( 'woocommerce_external_add_to_cart', 'woocommerce_external_add_to_cart', 30 );
add_action( 'woocommerce_external_add_to_cart', 'rei_external_add_to_cart', 30 );
function rei_external_add_to_cart(){
global $product;
if ( ! $product->add_to_cart_url() ) {
return;
}
$product_url = $product->add_to_cart_url();
$button_text = $product->single_add_to_cart_text();
do_action( 'woocommerce_before_add_to_cart_button' ); ?>
<p class="cart">
<?php echo esc_html( $button_text ); ?>
</p>
<?php do_action( 'woocommerce_after_add_to_cart_button' );
}
Here is how you add target="_blank" to the links on archive pages:
function ns_open_in_new_tab($args, $product)
{
if( $product->is_type('external') ) {
// Inject target="_blank" into the attributes array
$args['attributes']['target'] = '_blank';
}
return $args;
}
add_filter( 'woocommerce_loop_add_to_cart_args', 'ns_open_in_new_tab', 10, 2 );
Replace ns_ part with your own namespace abbreviation.
Remove above funtion from function.php:
Use plugin files from Template folder by Template Overwrite method and then
follow below path:
woocommerce\templates\single-product\add-to-cart\external.php
open external.php where there is a tag, apply target="_blank".
it will work.
I'm trying to deal with Wordpress 3.0. It's rather cool thing but I can't get on with one problem. For example, I have such menu tree. Menu tree is constructed from pages.
Home
news
video
audio
Blog
About author
Favourite colors
red
blue
green
My car
wheels
tires
The Idea is:
main menu consists of root elements: home, blog, my car
On the left side I would like to display children elements of current active root element.
For exammple if person is on the "home" page, on the left part he should see:
news
video
audio
If user is on the "Blog" page, he should see:
About author
Favourite colors
red
blue
green
I can't find an API to do that. Can you sugest me please where can I find it?
UPD:
#Jason McCreary
I've seen I've seen wp_list_pages() and tried it. I din't get how can I use it:
Please, see my template for a page:
<?php
/*
Template Name: page_news
* #package WordPress
* #subpackage Twenty_Ten
* #since Twenty Ten 1.0
*/
get_header(); ?>
<h1>page_news</h1>
<h1>Children menu:</h1>
<?php wp_list_pages('echo=0&child_of=8&title_li='); ?>
<div id="container">
<div id="content" role="main">
<?php
/** Get category id by name*/
//$catId = get_category_by_slug('news')->term_id;
query_posts('category_name=news');
get_template_part( 'loop', 'page' );
?>
</div><!-- #content -->
</div><!-- #container -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
See this line of code:
<?php wp_list_pages('echo=0&child_of=8&title_li='); ?>
I do have the page with id=8 (I see it in URL). Page with id=8 has several children.
I want to print them, but they are not printed. The output of the function wp_list_pages() is nothing.
I don't know why... :(
You can write a filter_hook to accomplish this.
My method: create an additional start_in argument for wp_nav_menu using my custom hook:
# in functions.php add hook & hook function
add_filter("wp_nav_menu_objects",'my_wp_nav_menu_objects_start_in',10,2);
# filter_hook function to react on start_in argument
function my_wp_nav_menu_objects_start_in( $sorted_menu_items, $args ) {
if(isset($args->start_in)) {
$menu_item_parents = array();
foreach( $sorted_menu_items as $key => $item ) {
// init menu_item_parents
if( $item->object_id == (int)$args->start_in ) $menu_item_parents[] = $item->ID;
if( in_array($item->menu_item_parent, $menu_item_parents) ) {
// part of sub-tree: keep!
$menu_item_parents[] = $item->ID;
} else {
// not part of sub-tree: away with it!
unset($sorted_menu_items[$key]);
}
}
return $sorted_menu_items;
} else {
return $sorted_menu_items;
}
}
Next, in your template you just call wp_nav_menu with the additional start_in argument containing the ID of the page you want the children off:
wp_nav_menu( array(
'theme_location' => '<name of your menu>',
'start_in' => $ID_of_page,
'container' => false,
'items_wrap' => '%3$s'
) );
I wrote this to print sub-navs of the pages you may be on. If you want to print out the sub-navigation for each of the pages, get the page parent instead of getting the ID. There would be more involved than that, but it's a start.
$menu = wp_get_nav_menu_items( 'Primary Menu' );
$post_ID = get_the_ID();
echo "<ul id='sub-nav'>";
foreach ($menu as $item) {
if ($post_ID == $item->object_id) { $menu_parent = $item->ID; }
if (isset($menu_parent) && $item->menu_item_parent == $menu_parent) {
echo "<li><a href='" . $item->url . "'>". $item->title . "</a></li>";
}
}
echo "</ul>";`
Check out wp_list_pages(). It is useful for providing child navigation in the sidebar.
mac joost's answer is great, but I would add that if you want the parent item to print, then you shouldn't unset the parent, so line 18 needs to be adjusted accordingly:
if($item->object_id != (int)$args->start_in) { unset($sorted_menu_items[$key]); }
have you seen wp_list_pages?
http://codex.wordpress.org/Function_Reference/wp_list_pages
look closer on child_of attribute
You can use Breadcrumb navxt plugin. It does exactly what you are looking for and its really great.
Breadcrumb NavXT Pugin
I've stopped to explore how to output custom part of worpress site taxonomy on the server-side. I just use jquery to copy active taxonomy branch from main menu and paste it to the page container I need.