WordPress Help Code


|| favicon icon:
   <link rel="shortcut icon" href="<?php echo get_stylesheet_directory_uri(); ?>/favicon.ico" />

|| shortcode
   [bestwebsoft_contact_form]
   <?php echo do_shortcode('[bestwebsoft_contact_form]'); ?>

|| Internal Server Error The server encountered an internal error or misconfiguration and was unable to complete your request.
   Please contact the server administrator webmaster@...

--How to Fix the Internal Server Error--
. At first check admin > settings > permalinks > select post name
. check for the corrupted .htaccess file
  /* http://www.wpbeginner.com/wp-tutorials/how-to-fix-the-internal-server-error-in-wordpress/ */


|| Cause of Free theme uses, footer link redirect
   wp index.php?theme_license=true

   This problem have to do solve:
   <?php
	/*  function.php just notice this following code in the end*/
		function wp_initialize_the_theme_load() { if (!function_exists("wp_initialize_the_theme")) {--------}
	 
	/*  replace up this code */
	 
		function wp_initialize_the_theme_load(){ 
			if (!function_exists("wp_initialize_the_theme")) { wp_initialize_the_theme_message(); die; } 
		} 

		function wp_initialize_the_theme_finish() {$uri = strtolower($_SERVER["REQUEST_URI"]); 
			if(is_admin() || substr_count($uri, "wp-admin") > 0 || substr_count($uri, "wp-login") > 0 ) { /* */ } else { /* */ } 
		} 
			wp_initialize_the_theme_finish();
	 
	/* now can change footer.php powered by link */ 

	/* if you want, You can remove this code. lib>Themater.php,*/
		if (!empty($_REQUEST["theme_license"])) {----}
		
	 
   ?>


Dynamic category show in a page:
==================================
<?php
 wp_list_categories('hide_empty=0&show_count=1&title_li=
 <h3>' . __('All Categories') . '</h3>' ); 
?>

WordPress Fix – Add Media Button Not Working:
=============================================
Basically you need to open your “wp-config.php” file in the root of your WordPress Install.
Search for this line:
  <?php require_once(ABSPATH . 'wp-settings.php'); ?>

And just before it add this code:
  <?php define('CONCATENATE_SCRIPTS', false ); ?>

/****************************/

Woocommerce:
===============

|| How To Change Product Images Size?
   1st woocommerce > setting > product > Display > Product Images
   2nd Regenerate Thumbnails plugins install and active
   tutorial link: https://www.youtube.com/watch?v=YVLb3eG0JdI
   

|| product detail page sku and category
   wp-content\plugins\woocommerce\templates\single-product\meta.php

|| Product listing page product name
   content-product.php
   <a href="<?php the_permalink(); ?>">---- </a>

|| product view page review tab remove

<?php
	add_filter( 'woocommerce_product_tabs', 'sb_woo_remove_reviews_tab', 98);
	function sb_woo_remove_reviews_tab($tabs) {

	 unset($tabs['reviews']);

	 return $tabs;
	}
?>

|| product view short description:
   woocommerce/single-product/short-description.php

|| breadcrumbs slash '/' replace as '>'
   function.php

<?php
	add_filter( 'woocommerce_breadcrumb_defaults', 'my_change_breadcrumb_delimiter' );
	function my_change_breadcrumb_delimiter( $defaults ) {
	 // Change the breadcrumb delimiter from '/' to '>'
	 $defaults['delimiter'] = ' > ';
	 return $defaults;
	}
?>

|| Default breadcrumbs remove from product page:
   function.php
   <?php remove_action( 'woocommerce_before_main_content','woocommerce_breadcrumb', 20, 0);?>

|| prodcut view page related product remove
   function.php
   <?php remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20 );?>

|| Add to cart remove:
        <?php
		/* product listing page add to cart remove */
		function remove_loop_button(){
			remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
		}
		add_action('init','remove_loop_button');
			or
		remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart' );
		
		/* product detail page add to cart remove */
		remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
		
	?>

|| Price Remove
       <?php
		/* product listing page price remove */
		remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );
		/* product detail page price remove */
		remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
		
	?>

|| Where to go to edit shop/products page:

Editing the layout of items within the shop page (or any other product archive such as category, tag, etc) can be done through template files.
you need to add a folder to your theme named "woocommerce" and copy the contents from the woocommerce plugin folder under "templates"
the loop folder contains the files you want to use - that and archive-product.php
so, in your theme, you'd have something like
themefolder/woocommerce/archive-product.php
themefolder/woocommerce/loop/...
<?php
	do_action( 'woocommerce_sidebar' )
?>


|| Dynamic Product Category in sidebar:
   Appearance > Widget:
   drag and drop (WooCommerce Product Categories) in (primary sidebar) or (secondary widget area)

|| Dynamic product category anywhere:
   function.php

<?php
	/* product category */
	function wooCommerceCategories() {

		$taxonomy     = 'product_cat';
		$orderby      = 'name';  
		$show_count   = 0;      // 1 for yes, 0 for no
		$pad_counts   = 0;      // 1 for yes, 0 for no
		$hierarchical = 1;      // 1 for yes, 0 for no  
		$title        = '';  
		$empty        = 0;

		$args = array(
			'taxonomy'     => $taxonomy,
			'orderby'      => $orderby,
			'show_count'   => $show_count,
			'pad_counts'   => $pad_counts,
			'hierarchical' => $hierarchical,
			'title_li'     => $title,
			'hide_empty'   => $empty
		);
		$all_categories = get_categories( $args );
		 foreach ($all_categories as $cat) {
			if($cat->category_parent == 0) {
				$category_id = $cat->term_id;       
				echo '<br /><a href="'. get_term_link($cat->slug, 'product_cat') .'">'. $cat->name .'</a>'; 
				$args2 = array(
						'taxonomy'     => $taxonomy,
						'child_of'     => 0,
						'parent'       => $category_id,
						'orderby'      => $orderby,
						'show_count'   => $show_count,
						'pad_counts'   => $pad_counts,
						'hierarchical' => $hierarchical,
						'title_li'     => $title,
						'hide_empty'   => $empty
				);
				$sub_cats = get_categories( $args2 );
				if($sub_cats) {
					foreach($sub_cats as $sub_category) {
						echo  $sub_category->name ;
					}   
				}
			}       
		}
	}
	/**/
?>

/* function call */

<div class="product_category col-lg-1 col-md-2">
     <?php if(function_exists("wooCommerceCategories")) wooCommerceCategories(); ?>
</div>


/************************************/

|| Dashboard page href link
   <a href="index.php?page_id=###"></a>

|| separate menu click then separate content show
   twentythirteen > page.php 


|| Add Font Awesome CDN To WordPress Without A Plugin

   /* Add the Following Code to Your Theme’s functions.php File: */
   <?php
	add_action( 'wp_enqueue_scripts', 'prefix_enqueue_awesome' );
	/**
	 * Register and load font awesome CSS files using a CDN.
	 *
	 * @link   http://www.bootstrapcdn.com/#fontawesome
	 * @author FAT Media
	 */
	function prefix_enqueue_awesome() {
		wp_enqueue_style( 'prefix-font-awesome', '//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.min.css', array(), '4.0.3' );
	}
   ?>


For Layout
=============
<?php
|| style.css

/*
Theme Name: LenzKarft
Theme URI: http://fsb.com.bd/
Description: A clean theme completely compatible with WordPress 4.1
Author: FSB
Author URI: http://fsb.com.bd/
Version: 1.4
*/
--------------------------
?>

|| header
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US">

<!-- BEGIN html head -->
	<head profile="http://gmpg.org/xfn/11">
		<meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>" />
		<meta name="viewport" content="width=device-width">
		<title><?php bloginfo('name'); ?> <?php wp_title(); ?></title>
		<link rel="stylesheet" type="text/css" media="all" href="<?php bloginfo('stylesheet_url'); ?>" />
		<?php wp_head(); ?>		
	</head>
<!-- END html head -->

<!-- Start Body from here -->
	<body>
		<div id="wrapper">
			<div id="header"></div>
------------------------------------


|| Footer	
			<div class="clear"></div>
			<div id="footer"></div>
		</div><!-- End wrapper-->
	</body><!-- End Body -->
</html>
------------------------------------
|| if this get css, you have to go wordpress>wp-includes>admin-bar.php
search this: /*function _admin_bar_bump_cb()*/

html{margin-top:32px;}

--------------------------------------------

Custom page Create
==================
1st step: include this in custom page
<?php 
/*
 Template name:Demo
*/
get_header() ;

?>

2nd step: Then go to backend add new page > right side > page attribute > Template

---------------------------------------------------------------------------------

Custom widget page Create
==========================
1st step: include this in custom page

<?php 
get_header() ;
/*
Template Name:demo_2;
*/
?>

2nd step: Then go to backend add new page> right side> page attribute>Template

3rd step:
<?php
function twentythirteen_widgets_init() {
    register_sidebar( array(
   	 'name'      	=> __( 'Main Widget Area', 'twentythirteen' ),
   	 'id'        	=> Demo2',
   	 'description'   => __( 'Appears in the footer section of the site.', 'twentythirteen' ),
   	 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
   	 'after_widget'  => '</aside>',
   	 'before_title'  => '<h3 class="widget-title">',
   	 'after_title'   => '</h3>',
    ) );
}

?>

4th step: go to backend widgets>
--------------------------------------------------------
Register widget areas.
==========================
<?php
/**
 * Register widget areas.
 */
function twentyfourteen_widgets_init() {
	
	register_sidebar( array(
		'name'          => __( 'Primary Sidebar', 'twentyfourteen' ),
		'id'            => 'sidebar-1',
		'description'   => __( 'Main sidebar that appears on the left.', 'twentyfourteen' ),
		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
		'after_widget'  => '</aside>',
		'before_title'  => '<h1 class="widget-title">',
		'after_title'   => '</h1>',
	) );
	register_sidebar( array(
		'name'          => __( 'Content Sidebar', 'twentyfourteen' ),
		'id'            => 'sidebar-2',
		'description'   => __( 'Additional sidebar that appears on the right.', 'twentyfourteen' ),
		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
		'after_widget'  => '</aside>',
		'before_title'  => '<h1 class="widget-title">',
		'after_title'   => '</h1>',
	) );
	register_sidebar( array(
		'name'          => __( 'Footer Widget Area', 'twentyfourteen' ),
		'id'            => 'sidebar-3',
		'description'   => __( 'Appears in the footer section of the site.', 'twentyfourteen' ),
		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
		'after_widget'  => '</aside>',
		'before_title'  => '<h1 class="widget-title">',
		'after_title'   => '</h1>',
	) );
}
add_action( 'widgets_init', 'twentyfourteen_widgets_init' );
?>
---------------------------------------------------------------

Pages based Navigation Menu
===============================
<!-- Start Navigation Menu -->
	<div id="nav-menu">
		<ul>
			<li class="page_item"><a class="first" href="<?php bloginfo('url'); ?>" title="<?php bloginfo('description'); ?>"><?php _e('Home', 'w3p'); ?></a></li>
			<?php wp_list_pages('sort_column=menu_order&depth=1&title_li='); ?>
		</ul>
	</div>
<!-- End Navigation Menu -->


Dashboard Appearance > Menu
================================
<!-- This code include in functions.php file-->
	<?php
		add_action('admin_menu', 'my_plugin_menu');
		
		function my_plugin_menu() {
			add_theme_page('My Plugin Theme', 'My Plugin', 'edit_theme_options', 'my-unique-identifier', 'my_plugin_function');
		}
	?>

Appearance menu show in header.php file
========================================
<?php wp_nav_menu(array('theme_location' => 'primary', 'container_class' => 'w3-menu', 'container' => 'nav')); ?>

Page Content anywhere
========================
<?php
	$id = 20;
	$p = get_page($id);
	echo apply_filters('the_content', $p->post_content);
?>

ALL post show
=====================
<?php if ( have_posts() ) : while ( have_posts() ) : the_post();
	the_content();
	endwhile; else: ?>
	<p>Sorry, no posts matched your criteria.</p>
<?php endif; ?>

Single post show By ID
=======================
---Post Title---
<?php echo get_the_title($ID); ?> 

---Only Post----
<?php
	$my_postid = 1;//This is page id or post id
	$content_post = get_post($my_postid);
	$content = $content_post->post_content;
	$content = apply_filters('the_content', $content);
	$content = str_replace(']]>', ']]&gt;', $content);
	echo $content;
?>
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s