Wordpress functions.php does not affect the theme - php

I am trying to customize my pre bought theme. What i try is, to have different menus for each page without using a plugin. Original theme has a function about navigation which uses walker class. here is the file in the original.entrepreneur theme. http://pastebin.com/TeT8hi7z.
I use Entrepreneur Child Theme. I want to use primary navigation in home page and turkish navigation in turkish flag. I added functions.php and I added the code below:
if (is_page('AOE Home')){
wp_nav_menu(array('menu'=>'Primary Navigation' ));
} elseif (is_page('turkish')) {
echo "text";
wp_nav_menu(array('menu'=>'Turkish Navigation' ));
}
But navigation elements stays same. Can you help me to solve my problem?
Thanks

Related

WordPress Grooni Crane Theme Content before the menu bar feature

I am using a licenced version of the WordPress Grooni Crane theme
https://crane.grooni.com/promo/
https://grooni.com/docs/crane/search/crane_before_primary_menu_area
I want to add content and images to a section ABOVE the Groovy Menu Plugin (comes with the Grooni theme).
So usually I would create te HTML of the images and content and forcefully add it into the header.php file before the menu gets shown, but upon doing this I saw that the PHP now allows for a content section to be added / displayed before the menu will be displayed using crane_before_primary_menu_area .
My question is: How / where in the Grooni Crane theme do I create / edit this section, so that I dont have to force the HTML into the header file, but so that it rather get added dynamicly using the proper functions.
Code in the header.php file looks like this:
do_action( 'crane_before_primary_menu_area' );
do_action( 'crane_primary_menu_area' );
do_action( 'crane_after_primary_menu_area' );
So it shows 'crane_before_primary_menu_area' first, then it shows the menu bar, and then it should show 'crane_after_primary_menu_area'.
My Question is where / how (on the wordpress CMS) do I create / edit a content section for 'crane_before_primary_menu_area' & 'crane_after_primary_menu_area'
This must be done through the child theme.
Together with the Crane theme It was bundled.
Activate it or create your own new one.
https://developer.wordpress.org/themes/advanced-topics/child-themes/
Insert the hook into the functions.php file that will be called in the action 'crane_before_primary_menu_area'
Sample contents of functions.php for child theme
<?php
if ( ! function_exists('custom_func__crane_before_primary_menu_area')) {
add_action( 'crane_before_primary_menu_area', 'custom_func__crane_before_primary_menu_area' );
function custom_func__crane_before_primary_menu_area() {
$html_content = '<div>Content before menu area</div>';
echo $html_content;
}
}
In the above example, we assigned HTML text to the variable
$html_content = '<div> Content before menu area </div>';
And immediately it was shown to the front
echo $html_content;
However inside the function
function custom_func__crane_before_primary_menu_area () {.......}
you can call any other available functions, and display any content you wish.

Wordpress child theme breaks site appearance

I am using Splash theme from StylemixThemes. I am trying to create a child theme in order to edit some things but when I am activating it I do not get the same result as the parent theme.
Inside the child theme folder I have the style.css and the functions.php. Here is the functions.php code
<?php
add_action('wp_enqueue_scripts', 'enqueue_parent_theme_styles'); function enqueue_parent_theme_styles() {
wp_enqueue_style('parent-style', get_template_directory_uri().'/style.css'); }
I am attaching a screenshot for both parent and child theme to show the difference.
parent
child
I am wondering if there is a solution or if there is something I am missing.
Thanks in advance!
You can create your custom child theme learning from wpbeginner.com

Is it possible to insert shortcode inside Header menu or top-bar menu in wordpress?

I have made a simple shortcode for my wordpress theme. I'm trying to align it on right-side above the corner of my page. Is it possible to insert shortcode function.php?
I want to place my Short-code in the top-bar (right side above the corner) so that it will work for each pages. Means if i click on any menu then the shortcode should have to work on that menu also.
Actually i'm new in web development. Please suggest me what shall i have to do so it will align where i want and should have work for each module.
You can use wordpress function for that. Please open the file on which you have to place shortcode. Like if you want to place it on header open header.php and add
<?php echo do_shortcode('[your_shortcode]'); ?>
where you want your shortcode content to appear
The best way is to find the top bar menu hook of your theme and then add this code (adapted for your needs) in your function.php child theme :
function my_shotcode_inside_top_bar ( $items, $args ) {
if (is_page() && $args->theme_location == 'secondary') {
$items .= '<li class="my-class">' . do_shortcode( "[my_shortcode]" ) . '</li>';
}
return $items;
}
add_filter( 'wp_nav_menu_items', 'my_shotcode_inside_top_bar', 10, 2 );
is_page displays the shortcode in pages only but you can choose another condition or no condition at all.
secondary is the hook and it depends on your theme. You can normally find it in your theme header.php file.
A menu location selector should be added - that way some themes support multiple menus, and some are called "top" or custom added.
The shortcode could then contain a call to whatever a menu position is:
EG: [myshortcode menu="secondary"]
Didn't have enough points to add this as a comment.

Woocommerce shop page custom template

As I understand by default Woocommerce shop page uses product archive template. What I am looking for, is to use a custom template for shop page.
Here is what I did:
Create template "my-shop"
Create page "My shop" -> choose template "my-shop"
Choose "My shop" as Woocommerce shop page
But none of the changes I made to "my-shop" template are present on the shop page.
What am I missing here? I would not like to change product archive itself, just the shop page.
Is there a way to disable product archive from being a default for shop page?
Thanks
I know it's too late and you may have figured it out by now. In any case, the changes that you would like to make to the WooCommerce Shop Page need to be done in the archive-product.php and it would be safer to create a child theme and do these changes. Making enhancements and customizations in a Child theme is best practice so that you can update the parent theme at any time and it won't affect your store.
I hope this helps, for more information on how you can use WooCommerce short-codes to customize your store can be found here.
To add to Silver Ringvee's answer - he used is_page but that only works on wordpress pages. For woocommerce you need to use something like is_woocommerce() . See Woocommerce conditional tags page.
My example code uses the is_shop conditional tag as that was the page you wanted to change. the code get_template_part( 'content', 'shop' ); will call the file content-shop.php in your theme root folder. This code is to be added at the top of wp-content\themes\*theme*\woocommerce\archive-product.php that you can copy from wp-content\plugins\woocommerce\templates\archive-product.php
You can add it just before get_header( 'shop' ); line 23 in my file - and the entire page will be drawn from your template. If you want to keep the header of the shop page, then put this code after the get_header code. Remember to include a footer in your file as well
if (is_shop()) {
get_template_part( 'content', 'shop' );
} else {
#normal archive-product code here
}
The solution (not perfect) that I figured to work best, until someone finds a way to actually change the template from dashboard:
Adding:
<?php
if (is_page( 'Page Title' ) ):
# Do your stuff
endif;
?>
to content-product.php in my theme's woocommerce folder.
If you prefer to go with code, you can create a redirect from the original shop page to your page via wp_redirect.
add_action('template_redirect', 'bc_010101_redirect_woo_pages');
function bc_010101_redirect_woo_pages()
{
if (is_shop())
{
wp_redirect('your_shop_url_here');
exit;
}
}
More detailed tutorial can be found here
This is not possible to create custom template for shop page , just copy and paste woocommerce Templates into you theme folder and Try to work in content-product.php template .

Wordpress Custom Navigation on Secondary Theme

I've followed the codex; http://codex.wordpress.org/Navigation_Menus
However I believe that because we are trying to do the edits on page that isn't using the main sites theme, it's falling apart.
Our standard theme is Grand College, the theme however we are trying to edit is a BlankSlate theme.
I've made the edits in the BlankSlate functions file and inserted:
function register_my_menu() {
register_nav_menu('example-menu',__( 'EXAMPLE Menu' ));
}
add_action( 'init', 'register_my_menu' );
In the header file I've inserted;
<?php wp_nav_menu( array( 'theme_location' => 'example-menu' ) ); ?>
And in the WP-admin dashboard I've built a menu for 'example': I've added Home and Contact to it. However in the 'Manage Location' section I've only got 2 menu options which is what Grand College gives you by default
However when I view the site, I get the 'main' navigation showing rather than just the example menu.
Do my edits to put a new custom menu in, have to be done on the Grand College theme (The sites standard theme, or am I right to be trying to edit the pages theme?
Any help would be great appreciated.
To register a navigation menu i simply used the following code-
register_nav_menu('example-menu',__( 'EXAMPLE Menu' ));

Categories