Searchform not showing up - wordpress

I have made a custom searchform.php to go with a Genesis child theme! However my custom form is being replaced by the Genesis Default Searchform.
In the child theme's functions.php page I have added this snippet....
function search_form_no_filters(){
// look for local searchform template
$search_form_template = locate_template( 'searchform.php' );
if ( '' !== $search_form_template ){
// searchform.php exists, remove all filters
remove_all_filters('get_search_form');
}
}
add_filter( 'get_search_form', 'genesis_search_form' );
This naturally should pull up my custom form and replace the Default Gensis one but for some reson it's not!
Have I missed something out here?
Many thanks.

I think add_filter part is the reason for the form not being displayed.
use add_filter( 'get_search_form', 'search_form_no_filters' );

Related

Wordpress Shortcode for keywords?

So, I know you can put:
function page_title_sc( ){
return get_the_title();
}
add_shortcode( 'page_title', 'page_title_sc' );
Into function.php to fetch the page title and get a [page_title] shortcode within Wordpress, but is it possible to do exactly that for keywords?
I put a focus keyword down in Yoast SEO and I would like to have a shortcode for that.
Or another idea: is there a way to have a custom shortcode field in every page? So that I only have to put something into that once and can use it as a shortcode within the whole page?
If you want a shortcode for Yoast to output the keyphrase automatically:
function wpso_61018203_output_yoast_keyphrase() {
// Make sure Yoast is installed/active.
if ( class_exists( 'WPSEO_Meta' ) ) :
// Hold the global post object.
global $post;
return WPSEO_Meta::get_value( 'focuskw', $post->ID );
endif;
}
add_shortcode('yoast_kw', 'wpso_61018203_output_yoast_keyphrase' );
You can then do this ['yoast_kw'] in your content, or use echo do_shortcode('[yoast_kw]'); in your template.
Use get_post_meta and grab _yoast_wpseo_focuskw:
function page_focus_keyword( ){
return get_post_meta(get_the_ID(), '_yoast_wpseo_focuskw');
}
add_shortcode( 'focus_keyword', 'page_focus_keyword' );
WordPress filters all content to make sure that no one uses posts and page content to insert malicious code in the database. This means that you can write basic HTML in your posts, but you cannot write PHP code.
And you want to use Wordpress shortcode for focus keyword.
Possible solution given on Wordpress.org Yoast SEO plugin support query on similar query, and checkout the linked solution
insert the below php snippet in functions.php
if(!function_exists('wpseoFocusKW'))
{
function wpseoFocusKW()
{
$focuskw = wpseo_get_value('focuskw', $post->ID);
echo $focuskw;
}
}
And to use the shortcode in another page for focused keyword, insert the below shortcode in any pages with yoast-seo plugin :
Shortcode for focus keyword
[<?php wpseoFocusKW();?>]

Wordpress, dokan errors to upload banner

I had errors when uploading banners and photos, I know I must put this code in the child theme to repair it, but I'm using the handy store theme for my store and I have not created any child theme.
Can someone explain me where I should place the code to fix the error?
my code:
function mgt_dequeue_stylesandscripts() {
if ( class_exists( 'woocommerce' ) ) {
wp_dequeue_style( 'select2' );
wp_deregister_style( 'select2' );
wp_dequeue_script( 'select2');
wp_deregister_script('select2');
} }
Should I put the code in the file 'function' of the theme 'handy store'? or one of dokan?
The best is to put your function in functions.php, but it will never work without a triggered action.
With your code you will need to add something like this :
add_action('wp_enqueue_scripts', mgt_dequeue_stylesandscripts, 99);
The last parameter (99) is the priority, the action will trigger later with higher number.

How to create Custom Pagination Permalinks in wordpress

I have an article with several pages in my wordpress blog. if for example i have the following link in my blog :
http://example.com/heartbreaking-photos
any idea how can i change the link of the second page from
http://example.com/heartbreaking-photos/2
to http://example.com/heartbreaking-photos/CUSTOM-STRING
CUSTOM-STRING aimed to be a custom title inside the page
To achieve this, you will need to do 2 things:
Disable the default WordPress canonical redirect - this is necessary, because WordPress will always redirect to the /2/ page when it encounters the page parameter in the URL or query args.
Add a custom rewrite rule to direct your custom title to the second page of your page - this is essentially necessary to allow the link format that you want.
In terms of code, this is what you need (this is a working solution, I've just tested it locally):
// Removes the canonical redirection
remove_filter( 'template_redirect', 'redirect_canonical' );
// Add custom rewrite rules
add_action( 'init', 'my_add_custom_rewrite_rules' );
function my_add_custom_rewrite_rules() {
// Slug of the target page
$page_slug = 'heartbreaking-photos';
// Page number to replace
$page_num = 2;
// Title you wish to replace the page number with
$title = 'custom-string';
// Add the custom rewrite rule
add_rewrite_rule(
'^' . $page_slug . '/' . $title . '/?$',
'index.php?pagename=' . $page_slug . '&page=' . $page_num, 'top'
);
}
There are three things you might want to configure or change here:
$page_slug - this is the slug of your page, in your case this is heartbreaking-photos
$page_num - the number of your pagination page, in your case this is 2
$title - the title you wish to use instead of your page number 2.
Feel free to alter the code as you wish, or copy it to cover more additional cases, similar to this one.
EDIT
Important: Once you use the code, go to Settings > Permalinks and click the "Save Changes" button. This will rebuild your rewrite rules, and is necessary for the solution to work.
Hope that helps. Let me know if you have any questions.
You can try this codex. Pass the arg and you will get page id, page title and use those
https://codex.wordpress.org/Function_Reference/get_pages
Or you can call page title by page id
$pagetitle= get_post_field( 'post_title', $page_id );
Ok, so basically you don't want to display the navigation link under the page (use css or modify the post template in the child theme) and add your custom link. If I understand it well:
Remove navigation links (depends on your theme, but basically):
.nav-links { display: none; }
You can add the custom link through function + custom fileds:
create a custom field, for example "my-url" in your post, see codex: https://codex.wordpress.org/Custom_Fields
add to your functions.php (in the child theme or in a custom site plugin):
function my_page_add_to_content( $content ) {
if ( ! empty(get_post_meta( get_the_ID(), 'my-url', true ) ) {
$content .= 'URL TEXT HERE'
}
return $content;
}
add_filter( 'the_content', 'my_page_add_to_content' );

WooCommerce - How to remove sidebar

I need to remove sidebar into my woocommerce store.
I have tried with backend in option theme and in each category but resultless.
I tried also:
1.file wp-template-hooks.php
removed--> do_action(..
2.file archive-product.php
removed--> do_action(..
insert in file function.php in theme dir and function.php in woocommerce dir
remove_action( 'woocommerce_sidebar', 'woocommerce_get_sidebar', 10 );
into database there is 2 tables with 2 fields serialised but is a risk change this.
resulless.
I finished the ideas.
Where is saved into db the visibility of sidebar? or the variable?
Can you help me?
Thanks
Ale
I just wanted to update this post for WooCommerce version 3.2.3 - 2017
OK the WooCommerce Plugin includes a folder with all the template files if you want to make changes to the template on a custom theme or child theme you need to copy all of the desired template into a folder called woocommerce in your root theme folder. This will overwrite the plugin templates and will allow for WooCommerce updates with overwriting your custom changes. These templates have all of the do_actions and hooks in the comments so it makes it easy to understand how it's working.
That said WooCommerce has hooks that allow for you to add or remove blocks of code you can check out the API Docs here.
To remove the side bar you need to add this into your functions.php file in your theme setup function
remove_action( 'woocommerce_sidebar', 'woocommerce_get_sidebar', 10 );
Please, add this code to your functions.php
function mb_remove_sidebar() {
return false;
}
add_filter( 'is_active_sidebar', 'mb_remove_sidebar', 10, 2 );
Add to functions.php the following line:
add_action( 'init', function () {
remove_action( 'woocommerce_sidebar', 'woocommerce_get_sidebar', 10 );
} );
You have already integrated WooCommerce in your theme?
If not, try to do this three steps for integration WooCommerce in your theme.
After that, remove get_sidebar(); from your_theme/woocommerce.php
It works fine for me. Screenshot here.
Hope it helps.
Further to #maksim-borodov's answer, I wanted to hide the sidebar conditionally, i.e. only on Product pages. Here's how:
function remove_wc_sidebar_conditional( $array ) {
// Hide sidebar on product pages by returning false
if ( is_product() )
return false;
// Otherwise, return the original array parameter to keep the sidebar
return $array;
}
add_filter( 'is_active_sidebar', 'remove_wc_sidebar_conditional', 10, 2 );
Add to functions.php the following line:
remove_action( 'woocommerce_sidebar', 'woocommerce_get_sidebar', 10);
I am using GeneratePress (free version), so the other solutions didn't work for me.
This page gave me the answer: https://docs.generatepress.com/article/sidebar-layout/#sidebar-filter
add_filter( 'generate_sidebar_layout', function( $layout ) {
// If we are on a woocommerce page, set the sidebar
if ( function_exists( 'is_woocommerce' ) && is_woocommerce() ) {
return 'no-sidebar';
}
// Or else, set the regular layout
return $layout;
} );
This can be done by woocommerce sidebar plugin. If you want to remove by code add this code to functions.php,
if (!class_exists( 'WooCommerce' ) ) {return;}
if(is_cart() || is_checkout() || is_product() || is_shop() || is_account_page()){
?>
<style type="text/css">
#secondary {
display: none;
}
#primary {
width:100%;
}
</style>
<?php
}
}
Here is how to remove the sidebar :-
go to wp-content/plugins/woocommerce
in file single-product.php remove the following code -
<?php
/**
* woocommerce_sidebar hook
*
* #hooked woocommerce_get_sidebar - 10
*/
do_action('woocommerce_sidebar');
?>
next edit the file archive-product.php and remove the following code -
<?php
/**
* woocommerce_sidebar hook
*
* #hooked woocommerce_get_sidebar - 10
*/
do_action('woocommerce_sidebar');
?>
(tip* before deleting this, copy and paste the entire code from this page into a seperate text file on your HD...that way you can always paste the original code back into this folder if anything goes wrong)

hijack get_template_part via plugin

I'm trying to do a plugin that will change the behavior of a theme.
In the theme file I have a get_template_part('libs/templates/user_menu');
I want to make my plugin to "force" the get_template_part return another slug file (a path to a file in plugin folder).
So far this is my code inside the plugin:
function wpse21352_template_part_cb( $slug )
{
if(slug == 'user_menu') {
return WP_PLUGIN_URL.'/'.$slug;
} else {
return $slug;
}
}
do_action( "get_template_part_user_menu", 'user_menu' );
add_action( 'wpse21352_template_part_cb', 'get_template_part_user_menu', 10, 1 );
First of all, get_template_part does not return anything. It loads a file from your theme based on the parameters you pass to it. The function does not support filtering, which means you can not actually overwrite what is outputted by get_template_part.
The only thing the action get_template_part_[slug] allows you to do is output something before the theme file is loaded. For example, using
function myplugin_before_login( $slug, $name ) {
echo 'Example';
}
add_action( 'get_template_part_login', 'myplugin_before_login', 10, 2 );
would output "Example" before the loading the theme file when calling get_template_part( 'login' );.
Actions and filters
In general, however, I believe you might misunderstand how actions and filters work. The WordPress Codex offers extensive information on their use and usage.

Resources