Is there any way to add categories for each Page. I am asking it because I see categories option only for posts.
You Can Add the following code in functions.php in your theme folder:
function myplugin_settings() {
// Add tag metabox to page
register_taxonomy_for_object_type('post_tag', 'page');
// Add category metabox to page
register_taxonomy_for_object_type('category', 'page');
}
// Add to the admin_init hook of your theme functions.php file
add_action( 'init', 'myplugin_settings' );
I think plugin Add Category to Pages will help you to add categories with pages.
Related
I using wordpress and woocommerce plugin and added custom html button on product page. I did it in function.php file. How can i get PDF file with photo content from every product page after click on my button?
add_action( 'woocommerce_after_single_product_summary', 'custom_button_on_product_page' );
function custom_button_on_product_page() {
global $product;
echo '<button class="send_button">SEND PDF</button>';
}
function enqueue_jspdf() {
wp_enqueue_script( 'jspdf', 'https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.5.1/jspdf.umd.min.js', array(), '2.5.1', true );
}
add_action( 'wp_enqueue_scripts', 'enqueue_jspdf' );
How can i do it? Help please. I tried add jsPDF library in function.php too and paste javascript code in code snippet. But i don't now how to hook on my code to photo content in product page. Great thanks for your answers
I am trying to add a shortcode to all my woocommerce single product pages. I want the shortcode to appear above the short description.
I have found this code and added it to functions.php, but I can see that it adds the shortcode below the short description (and above the add to cart button).
add_filter('woocommerce_short_description','ts_add_text_short_descr');
function ts_add_text_short_descr($description){
$text = do_shortcode('[my-shortcode]');
return $description.$text;
}
I would be very gratefull for some help :)
function customShortcodeBeforeShortDescription( $post_excerpt )
{
echo do_shortcode('[wpqr-code]');
}
add_filter('woocommerce_short_description','customShortcodeBeforeShortDescription', 10, 1);
You can use the woocommerce_single_product_summary action hook. try the below code. The code will go in your active theme functions.php file.
function add_shortcode_before_short_description(){
echo do_shortcode( '[wpqr-code]' );
}
add_action( 'woocommerce_single_product_summary', 'add_shortcode_before_short_description', 15, 1 );
Tested and works
I'm working on a WordPress plugin where I've to create a custom frontend page. After adding the add_rewrite_tag, my custom frontend page works and all the woocommerce pages (endpoints) works fine but the /my-account page does not.
It shows the posts page. Removing the add_rewrite_tag fixes the /my-account page.
function customop_custom_output() {
add_rewrite_tag( '%pn-projects%', '([^/]+)' );
add_permastruct( 'pn-projects', '/%pn-projects%' );
flush_rewrite_rules();
}
add_action( 'init', 'customop_custom_output' );
Am I missing something here?
I have a page template that is a minimalized page (call it min-page.php) in my theme. I use it to remove the header and footer info and add in some basic links so the customer doesn't get distracted.
I can change this template in the Page Attributes on various WooCommerce pages (checkout, cart, my account) but I can't change it on the product page or the general shopping page that displays all the products.
How can I set these pages to use my page template?
You can change the single product template by using the following code via functions.php
function get_product_template($single_template) {
global $post;
if ($post->post_type == 'product') {
$single_template = dirname( __FILE__ ) . '/min-page.php';
}
return $single_template;
}
add_filter( 'single_template', 'get_product_template' );
Check the template path after placing the code.
I am trying to just display the wordpress categories in a metabox on a different page, the page is custom.
Like a blank page and I am trying to add the wordpress metabox on that page, and be able to add new categories.
Screencast example of what I want to achieve.
It's very simple, just call the following function
add_action( 'init', 'add_cat_meta' );
function add_cat_meta()
{
register_taxonomy_for_object_type( 'category', 'custom_page' );
}
Notice the custom_page, replace custom_page with your original custom post name, for example if you have following to register a custom post
register_post_type( 'restaurant',
array(...);
);
Now to add the category meta box for that custom post you can use
register_taxonomy_for_object_type( 'category', 'restaurant' );
Also, if you want to add the category meta box in the page section then you can use
register_taxonomy_for_object_type('category','page');
But pages are different than posts and don't require a category.