I want to add a custom url for the front page using YOAST. I'm trying this approach but it doesn't do anything, can you help me?
function design_canonical($url) {
global $post;
$url == ( 'www.cator.com/cator/');
}
add_filter( 'wpseo_canonical', 'design_canonical' );
any idea where is the problem?
thanks
You first need to check if your page is home or not which you can check through is_home()
function design_canonical($url) {
if (is_home()) {
return 'your-custom-url.com'; //Enter here your custom url
} else {
return $url;
}
}
add_filter( 'wpseo_canonical', 'design_canonical' );
Related
I want to redirect a custom url to another custom url in the website using a php snippet without .htaccess
I tried the code below but it doesn't work
add_filter('get_the_permalink','my_permalink_redirect');
function my_permalink_redirect($permalink) {
global $post;
if ($permalink = 'https://www.staging2.domain.com/shop/') {
$permalink = 'https://www.staging2.domain.com/event/';
}
return $permalink;
}
Not the most glamorous way to do it, but you could try echoing JS that does the redirect.
function redirect_from_shop() {
echo "<script>
var pagePath = window.location.pathname;
if (pagePath == '/shop/') {
window.location = 'https://www.staging2.domain.com/event/';
}
</script>";
}
add_action('wp_head', 'redirect_from_shop');
You can use the template_redirect action and wp_redirect to do this.
template_redirect fires right before the template is loaded, so you can check to see if WordPress is about to load the page you want to redirect from, and if it is, redirect to the new page.
add_action( 'template_redirect', function() {
// is_page takes a Page ID, title, slug, or array as a parameter
if ( is_page( 'shop' ) ) {
wp_redirect( 'https://www.staging2.tktshub.com/event/' );
die();
}
} );
I am using the Genesis framework and need to load a custom footer when a certain page template loads, but I am having issues passing the page template file name into the function. I cannot use the slug because the template can be used for multiple pages, so I really need to use the template file name instead. I believe I'm on the right path with what I have so far, but I don't quite understand what I'm reading about get_query_var and how it can help pass the value into my function.
So far my code is as follows:
remove_action( 'genesis_footer', 'genesis_do_footer' );
if (is_page_template( 'page-alternate.php' )) {
add_action( 'genesis_footer', 'do_alternate_footer' );
} else {
add_action( 'genesis_footer', 'do_main_footer' );
}
function do_alternate_footer() {
echo 'xxx';
}
function do_main_footer() {
echo 'yyy';
}
Any assistance would be greatly appreciated. Thank you
The "Is Page Template" function actually looks for the template page name not the file so in this example if the page template name was "alternate" you would have:
remove_action( 'genesis_footer', 'genesis_do_footer' );
$CurrPageTemplate = get_page_template_slug( get_queried_object_id() );
if ($CurrPageTemplate == 'page-alternate.php' ) {
add_action( 'genesis_footer', 'do_alternate_footer' );
} else {
add_action( 'genesis_footer', 'do_main_footer' );
}
function do_alternate_footer() {
echo 'xxx';
}
function do_main_footer() {
echo 'yyy';
}
See how you go with that.
I've a WordPress website and am trying to add a custom search option in the website's home page as well in the header section. Unfortunately I can't see any option to include it from the website's dashboard and decided to follow the link to create a custom one as follows:
Tutorial Link - Custom Search
and this is the code that I've tried same as the tutorial:
add_action('tickercontainer','add_search_to_footer'); //Guessinghere I've to declare the div class
function add_search_to_footer() {
get_search_form();
}
function SearchFilter($query) {
if ( !is_admin() && $query->is_search ) {
$query->set('post_type', 'post'); //OR USE 'PRODUCT'
}
return $query;
}
add_filter('pre_get_posts','SearchFilter');
function storefront_search_form_modify( $html ) {
return str_replace( array('Search …','Search'), array('WooCommerce Hooks, Storefront Theme, Google AdWords...','Search Article'), $html );
}
add_filter( 'get_search_form', 'storefront_search_form_modify' );
function new_nav_menu_items($items) {
$searchicon = '<li class="search"><i class="fa fa-search" aria-hidden="true"></i></li>';
$items = $items . $searchicon;
return $items;
}
add_filter( 'wp_nav_menu_additional-resources_items', 'new_nav_menu_items' );
Though I am not sure what I am missing here and would expect some ideas to implement in an appropriate way.
Note: Right now, after including the code above, I can't see the search option in the website.
I want to remove read-more link after calling the_content() function of wordpress. I want only to show content of each post in a loop and read-more link is redundant.
I try this code but read-more link remains after post content:
add_filter( 'the_content_more_link', 'disable_more_link', 10, 2 );
function disable_more_link( $more_link, $more_link_text ) {
return;
}
where I can find the code that adds this read-more link after the content?
You can use a filter to remove the read-more link from content. I have updated your filter. Please try it, It's working fine.
function disable_more_link( $link ) {
$link = preg_replace( '|#more-[0-9]+|', '', '' );
return $link;
}
add_filter( 'the_content_more_link', 'disable_more_link', 10, 2 );
More info
function new_excerpt_more($more) {
return '...';
}
add_filter('excerpt_more', 'new_excerpt_more');
I'm using the following snippet to change the URL but I want to make it dynamic rather than hard coding a link in.
add_filter( 'woocommerce_breadcrumb_home_url', 'woo_custom_breadrumb_home_url' );
function woo_custom_breadrumb_home_url() {
return 'http://woothemes.com';
}
I tried the following which not only breaks the link but it appears in the top of the screen.
$breadcrumb = bloginfo('url');
add_filter( 'woocommerce_breadcrumb_home_url', 'woo_custom_breadrumb_home_url' );
function woo_custom_breadrumb_home_url() {
return '$breadcrumb';
}
How can I make the Home link dynamic?
You can try
return home_url();
This should give you the same address as bloginfo('url')