Added the line of code in my function.php file
add_theme_support('post-thumbnails');
After going saving, and looking at my screen options, Featured images still wasn't showing. I even went as far back to check if my Custom Fields was correct and I had it unmarked to show
First: (I assume it's a typo in your description): Change function.phpto functions.php
Second: Try to call add_theme_support('post-thumbnails') within a function attached to the after_setup_theme hook as shown in the documentation.
// Register Theme Features
function custom_theme_features() {
// Add theme support for Featured Images
add_theme_support( 'post-thumbnails' );
}
// Hook into the 'after_setup_theme' action
add_action( 'after_setup_theme', 'custom_theme_features' );
I hope these steps will fix your issue, otherwise it would be necessary to provide more of your code
hi #EliCollins Use this code. It should work
add_action( 'after_setup_theme', 'theme_setup' );
function theme_setup() {
add_theme_support('post-thumbnails' );
}
I actually found out the answer just last night. In the CPT UI on the left hand side there is a settings area "Click headings to reveal available options.", click on the settings caret and at the bottom under supports select Featured Images. And then of course going into your function.php and adding
add_theme_support('post-thumbnails' );
Related
I am using WordPress and I installed the Woocommerce plugin.
I added the template folder in my theme and started to customize my theme.
Now, I have to remove the Woocommerce.css from my theme and I found code on the official website here
I added the same code in the function.php
add_filter( 'woocommerce_enqueue_styles', '__return_empty_array' );
or
add_filter( 'woocommerce_enqueue_styles', '__return_false' );
but both answers are not working. I have installed the 5.7.1 Woocommerce.
How can I solve this issue?
function.php
function customtheme_scripts() {
wp_enqueue_style( 'customtheme-style', get_stylesheet_uri(), array(), time() );
wp_style_add_data( 'customtheme-style', 'rtl', 'replace' );
wp_enqueue_script( 'customtheme-navigation', get_template_directory_uri() . '/js/navigation.js', array(), _S_VERSION, true );
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
wp_dequeue_style( 'customtheme-woocommerce-style' );
}
add_action( 'wp_enqueue_scripts', 'customtheme_scripts' );
view source
The domain name is just an example.
This answer has been fully tested on woocommerce 5.x+ and works fine on the default woo style sheets! If you're using a custom theme and/or custom style sheet then you may encounter some discrepancies.
What you see on the documentation page, no longer works on woo 4+, according to their github page.
So you need to dequeue its styles!
wp_dequeue_styleDocs
So if you only want to remove woocommerce.css file, then you could do this:
add_action('wp_enqueue_scripts', 'removing_woo_styles');
function removing_woo_styles()
{
wp_dequeue_style('woocommerce-general'); // This is "woocommerce.css" file
}
However, if you want to remove all of the style sheets loaded by woo, then you could use this:
add_action('wp_enqueue_scripts', 'removing_woo_styles');
function removing_woo_styles()
{
wp_dequeue_style('wc-block-vendors-style');
wp_dequeue_style('wc-block-style');
wp_dequeue_style('woocommerce-general');
wp_dequeue_style('woocommerce-layout');
wp_dequeue_style('woocommerce-smallscreen');
}
If you still can see the styles, then try to clean your cache.
UPDATE related to the question "custom style sheet"
At the time that I was writing the answer you had not provided any screenshot of your style sheet, nor did you say anything about using a custom style sheet. That's why you were not able to get it to work.
Please do NOT copy/paste if you're using a custom style sheet, like the custom css file used in the question. wp_dequeue_style function takes your style sheet handle as the argument. So please read the documentation first. You're using a custom handle name (i.e "customtheme-woocommerce-style"), therefore, you need to use that handle name.
add_action('wp_enqueue_scripts', 'removing_woo_styles');
function removing_woo_styles()
{
wp_dequeue_style('customtheme-woocommerce-style'); // This is your "custom style sheet" file.
}
Also note that commenting out the enqueue section in the main file (i.e inc/woocommerce.php) may work temporarily but on the next woo update, it'll come back again. So, it's recommended to avoid updating your template files as much as possible unless you really have to which is not the case here!
I'm working on a project that is running of a child theme of TwentySeventeen and whilst the rest of the site doesn't have a sidebar, WooCommerce seems to have it.
For example, the shop page has it - I have tried a few things already and none work without caveats or didn't work at all:
I tried copying archive-product.php to my theme dir in woocommerce/archive-product.php and removing the below:
do_action( 'woocommerce_after_main_content' );
This didn't work.
I then tried doing:
remove_action('woocommerce_sidebar','woocommerce_get_sidebar',10);
...this didn't work either.
I found this answer and it worked, but didn't make the page full width (still had space for the sidebar) and a comment on the answer noted using that method isn't a great idea.
I also found this answer but it involves adding CSS, something I'd like to avoid as it isn't the most robust method in-case class names change in the future etc...
Isn't there a proper way of doing this without potential side affects?
Please, add this code to your functions.php
For remove only woocommerce side bar
function disable_woo_commerce_sidebar_mms() {
remove_action( 'woocommerce_sidebar', 'woocommerce_get_sidebar', 10);
}
add_action('init', 'disable_woo_commerce_sidebar_mms')
for remove all side bars
function remove_sidebar_mms() {
return false;
}
add_filter( 'is_active_sidebar', 'remove_sidebar_mms', 10, 2 );
OR
You can try this with to increase the priority hope fully its work
remove_action('woocommerce_sidebar','woocommerce_get_sidebar',25);
With the help of Mannu saraswat's answer and some fiddling around I came up with a solution:
// Remove the sidebar
add_action('get_header', 'blm_wc_remove_sidebar_check', 10);
// Removes the sidebar
function blm_wc_remove_sidebar($index) {
return false;
}
// Check to see if we're on a WooCommerce page and if so, remove the sidebar
function blm_wc_remove_sidebar_check() {
if ( is_woocommerce() ) {
add_filter('is_active_sidebar', 'blm_wc_remove_sidebar', 10, 1);
}
}
This avoids having to do the is_active_sidebar check / filter addition on non-WooCommerce pages.
Maybe there is a cleaner way to do this, but this worked for me.
I want to display an activation message after activating the plugin.
I've seen a few questions on SO about this, but none of 'em work properly:
if (!get_option("startup")) {
echo "<div class='updated'><h3>Welcome to [name]</h3>";
update_option('startup', 'true');
}
That works.. kinda. It puts the HTML at the very top, even before the <!DOCTYPE>. Is there any way to put it at the right place? So in the body tag?
There's a few things you'll need to do here. Firstly, the register_activation_hook() function is used to hook into the activation of your plugin. And the admin_notices action is used to add a notice inside the admin area (you can't just print your notice out anywhere).
However, there's an additional complication in that you can't use the admin_notices action on plugin activation. This is because WordPress doesn't 'live activate' your plugin - it activates it in the background and suppresses the output in order to make sure, before completing the activation, that it doesn't trigger any fatal errors.
Fortunately, this blog post outlines a solution to this problem. The author of the post suggests using transients to save the 'state' of your plugin so that it can be retrieved once it has been activated.
Because that blog has a CC-BY-SA license like this site, I'll copy the code in here so it lives on. I've slightly condensed it to keep the length of this post down, but you can view the whole blog post for the full solution. I've also tested this to ensure it still works - and it does on my install of WordPress 4.5.3.
register_activation_hook( __FILE__, 'fx_admin_notice_example_activation_hook' );
function fx_admin_notice_example_activation_hook() {
set_transient( 'fx-admin-notice-example', true, 5 );
}
add_action( 'admin_notices', 'fx_admin_notice_example_notice' );
function fx_admin_notice_example_notice(){
/* Check transient, if available display notice */
if( get_transient( 'fx-admin-notice-example' ) ){
?>
<div class="updated notice is-dismissible">
<p>Thank you for using this plugin! <strong>You are awesome</strong>.</p>
</div>
<?php
/* Delete transient, only display this notice once. */
delete_transient( 'fx-admin-notice-example' );
}
}
I'm struggling with an issue registering my custom menu in WP. I have read all the text and various forums about custom menus in wp, but cannot seem to figure out how to get mine to work.
Here is the code snippet I am adding to my function.php file:
function register_my_menu() {
register_nav_menu('header-menu',__( 'Header Menu' ));
}
add_action( 'init', 'register_my_menu' );
and then adding this bit of code to the header.php file where I want the menu to be:
<?php wp_nav_menu( array( 'theme-location' => 'header-menu' ) ); ?>
Both snippets taken directly from: https://wordpress.org/support/topic/register_nav_menu-not-actually-registering-menus
Now I have tried entering these codes differently, in different orders, renaming them, to no avail. Nothing seems to work. When I view my WP site, I find the top part of the side has the functions.php code showing at the top and the option to edit the menu in the admin panel never appears.
Here is even a screen shot of the result i get when I use this code.
http://i.stack.imgur.com/5XiEu.jpg
Is there something I'm doing wrong???
IF so, how can I fix it?
I would be much obliged to get some assistance, as I am very new to WP.
Thanks for the responses, I finally figured it out!
At first I had not php tags.
Then I was adding an opening and then a closing tag: <?php and ?> at the end.
I picked apart the twenty-thirteen theme and then copied my code over to it.
I then realized, that the function.php file only needed the opening tag "<?php...and now all is good!
So my final code was:
<?php
function register_my_menu() {
register_nav_menu('header-menu',__( 'Header Menu' ));
}
add_action( 'init', 'register_my_menu' );
Worked like a charm!
Ok, so im working on a theme that I want to have different styles and php files depending on which design the user has chosen. How would I do this? The best example I can give is having a get_template_part function that changes directory based on the users selection of design. Heres my idea of how the code would kinda look.
<?php /*custom_function*/(/*Global Path variable which changes*/, '/filename') ?>
The x theme has like stacks I think which might be a similar idea. Thanks.
Maybe something like this in the function.php: (just an example)
<?php
define("DESIGN", "flat");
if(DESIGN == "flat"){
add_action( 'wp_enqueue_scripts', 'asd_scripts' );
}elseif(DESIGN == "notflat"){
// other add_action( 'wp_enqueue_scripts', '...' );
}
function asd_scripts() {
// load bootstrap js
wp_enqueue_script('asd-bootstrapjs', get_template_directory_uri().'/includes/resources/bootstrap/js/bootstrap.js', array('jquery') );
}
?>
You need to use the theme customization api to achieve this. For example you would use the customize_register hook:
function mytheme_customize_register( $wp_customize )
{
//All your sections, settings, and controls will be added here
}
add_action( 'customize_register', 'mytheme_customize_register' );
This hook allows you access to the $wp_customize object.
There are existing examples in the WordPress docs, this should get you started with what you would like to do.