Hi i want to add new custom title and links into My Account page into my WooCommerce site.. Searched all documentation, and Stackoverflow topics, but not found sollution for my request.
This is title for what im asking for
Text Muj Ucet is My Account in english. :)
i want to add new title like is shown in image bellow:
This is WooCommerce Template Code for that part:
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
?>
<p><?php
/* translators: 1: user display name 2: logout url */
printf(
__( 'Hello %1$s (not %1$s? Log out)', 'woocommerce'
),
'<strong>' . esc_html( $current_user->display_name ) . '</strong>',
esc_url( wc_logout_url( wc_get_page_permalink( 'myaccount' ) ) )
);
?></p>
<p>Na nástěnce svého uživatelského účtu si můžete stáhnout své zakoupené
produkty a faktury, upravit své osobní informace, změnit heslo nebo
fakturační adresu.</p>
<?php
/**
* My Account dashboard.
*
* #since 2.6.0
*/
do_action( 'woocommerce_account_dashboard' );
/**
* Deprecated woocommerce_before_my_account action.
*
* #deprecated 2.6.0
*/
do_action( 'woocommerce_before_my_account' );
/**
* Deprecated woocommerce_after_my_account action.
*
* #deprecated 2.6.0
*/
do_action( 'woocommerce_after_my_account' );
/* Omit closing PHP tag at the end of PHP files to avoid "headers already
sent" issues. */
I want to add new one title bellow that sidebar. How to register a new title ?
Thanks
Here is the solution.
add_filter('woocommerce_account_menu_items', 'display_account_new_link');
function display_account_new_link( $items ) {
$items['new_link'] = __( 'New Link', 'text-domain' );
return $items;
}
add_action( 'woocommerce_account_new_link_endpoint', 'new_account_link_content' );
function new_account_link_content() {
//include your display template here
echo "Here goes you content";
}
After pasting this code in your plugin or in your theme function.php file this code will make a new link in the my account navigation sidebar, along with the template you want to assign this link. Here new_link is the slug for this navigation link. If you want to give some different slug you must rename new_link written everywhere in the given code. As soon as you click on this New Link it will redirect you to the Page Not Found Page. It can be solved by adding this code.
add_action( 'init', 'register_new_link_endpoint');
function register_new_link_endpoint() {
add_rewrite_endpoint( 'new_link', EP_PAGES );
}
After pasting this code you must save your permalink once, by going to WordPress Dashboard->Settings->Permalinks and hit the save changes button.
Disclosure: I'm not a programmer, or trained in web design. Please forgive me if this is something stupid.
Today I've been trying to fix a problem with overlapping Masonry on my Wordpress.org website: nathanhewitt.net. I found that the likely solution was to use imagesLoaded, a jquery script (imagesloaded.desandro.com). since this isn't my area of expertise, I didn't know how to use a jquery script so I went through many different forums, primarily using this and this as my guides on how to add them to the theme's functions.php file.
This is what I added, toward the top of the code (I'll put the full code below):
function my_scripts_method() {
// register your script location, dependencies and version
wp_register_script('imagesLoaded',
get_template_directory_uri() . '/custom_jquery/imagesloaded.pkgd.min.js',
array('jquery'),
'1.0' );
// enqueue the script
wp_enqueue_script('imagesLoaded');
}
add_action('wp_enqueue_scripts', 'my_scripts_method');
As soon as I added it, I began to get a Parse error: syntax error, unexpected end of file in /home/nathanhe/public_html/wp-content/themes/balance2/functions.php on line 359, but no matter how I shift the code around, copying and pasting and changing the order, it always says line 359.
I should mention that the code I added related to imagesLoaded is no where near line 359, and also that I have put the text through an online php checker and it didn't find any errors.
Does anyone have any idea what I've done wrong?
I've checked around for several hours and can't seem to figure this out; hopefully someone out there might also be having the same problem and might run into this forum.
Here's the full code:
<?php
require_once ( get_stylesheet_directory() . '/theme-options.php' );
if (!is_admin()) {
wp_deregister_script( 'jquery' );
wp_register_script( 'jquery', get_bloginfo('stylesheet_directory').'/libs/jquery-1.6.1.min.js' );
wp_enqueue_script( 'jquery' );
wp_enqueue_script( 'jquery_masonry', get_bloginfo('stylesheet_directory').'/libs/jquery.masonry.min.js' );
wp_enqueue_script( 'jquery_ui', get_bloginfo('stylesheet_directory').'/libs/jquery-ui.custom.min.js' );
// javascript for infinite scroll
$imbalance2_theme_options = get_option('imbalance2_theme_options');
if ( $imbalance2_theme_options['navigation'] == 1 )
{
wp_enqueue_script( 'jquery_infinitescroll', get_bloginfo('stylesheet_directory').'/libs/jquery.infinitescroll.min.js' );
}
}
function my_scripts_method() {
// register your script location, dependencies and version
wp_register_script('imagesLoaded',
get_template_directory_uri() . '/custom_jquery/imagesloaded.pkgd.min.js',
array('jquery'),
'1.0' );
// enqueue the script
wp_enqueue_script('imagesLoaded');
}
add_action('wp_enqueue_scripts', 'my_scripts_method');
// shortcodes
function imbalance2_wide( $atts, $content = null )
{
return '<div class="wide">' . do_shortcode($content) . '</div>';
}
add_shortcode( 'wide', 'imbalance2_wide' );
function imbalance2_aside( $atts, $content = null )
{
return '<div class="aside">' . do_shortcode($content) . '</div>';
}
add_shortcode( 'aside', 'imbalance2_aside' );
// 210px width images for the grid
if ( function_exists( 'add_theme_support' ) )
{
add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 210 );
}
if ( function_exists( 'add_image_size' ) )
{
add_image_size( 'homepage-thumb', 210 );
}
// font output for css
function getFonts()
{
global $imbalance2_theme_options;
if ($imbalance2_theme_options['font'] == 0) return 'Georgia, "Times New Roman", Serif';
return '"Helvetica Neue", Helvetica, Arial, "Sans-Serif"';
}
// favicon for <head>
function getFavicon()
{
global $imbalance2_theme_options;
return '<link rel="shortcut icon" href="'.($imbalance2_theme_options['favicon'] != '' ? $imbalance2_theme_options['favicon'] : get_bloginfo('stylesheet_directory').'/favico.ico').'" />';
}
// color option for css
function getColor()
{
global $imbalance2_theme_options;
return $imbalance2_theme_options['color'] != '' ? $imbalance2_theme_options['color'] : '#f05133';
}
// fluid grid option for css
function fluidGrid()
{
global $imbalance2_theme_options;
return $imbalance2_theme_options['fluid'];
}
// images only option for css
function imagesOnly()
{
global $imbalance2_theme_options;
return $imbalance2_theme_options['images_only'];
}
// google analytics
function imbalance2google()
{
global $imbalance2_theme_options;
return $imbalance2_theme_options['google'];
}
// custom menu
class Imbalance2_Walker_Nav_Menu extends Walker_Nav_Menu {
function start_lvl(&$output, $depth) {
$indent = str_repeat("\t", $depth);
$output .= "\n$indent<div class=\"imbalance2_submenu_container\"><ul class=\"sub-menu\"><li><ul class=\"imbalance2_submenu\">\n";
}
function end_lvl(&$output, $depth) {
$indent = str_repeat("\t", $depth);
$output .= "$indent</ul></li></ul></div>\n";
}
}
/**
* Functions and definitions
*/
/**
* Set the content width based on the theme's design and stylesheet.
*
* Used to set the width of images and content. Should be equal to the width the theme
* is designed for, generally via the style.css stylesheet.
*/
if ( ! isset( $content_width ) )
$content_width = 720;
/** Tell WordPress to run imbalance2_setup() when the 'after_setup_theme' hook is run. */
add_action( 'after_setup_theme', 'imbalance2_setup' );
if ( ! function_exists( 'imbalance2_setup' ) ):
/**
* Sets up theme defaults and registers support for various WordPress features.
*
* Note that this function is hooked into the after_setup_theme hook, which runs
* before the init hook. The init hook is too late for some features, such as indicating
* support post thumbnails.
*
* To override imbalance2_setup() in a child theme, add your own imbalance2_setup to your child theme's
* functions.php file.
*
* #uses add_theme_support() To add support for post thumbnails and automatic feed links.
* #uses register_nav_menus() To add support for navigation menus.
* #uses add_custom_background() To add support for a custom background.
* #uses add_editor_style() To style the visual editor.
* #uses load_theme_textdomain() For translation/localization support.
* #uses add_custom_image_header() To add support for a custom header.
* #uses register_default_headers() To register the default custom header images provided with the theme.
* #uses set_post_thumbnail_size() To set a custom post thumbnail size.
*
* #since Twenty Ten 1.0
*/
function imbalance2_setup() {
// This theme styles the visual editor with editor-style.css to match the theme style.
add_editor_style();
// This theme uses post thumbnails
add_theme_support( 'post-thumbnails' );
// Add default posts and comments RSS feed links to head
add_theme_support( 'automatic-feed-links' );
// Make theme available for translation
// Translations can be filed in the /languages/ directory
load_theme_textdomain( 'imbalance2', TEMPLATEPATH . '/languages' );
$locale = get_locale();
$locale_file = TEMPLATEPATH . "/languages/$locale.php";
if ( is_readable( $locale_file ) )
require_once( $locale_file );
// This theme uses wp_nav_menu() in one location.
register_nav_menus( array(
'header-left' => __( 'Header Left Navigation', 'imbalance2' ),
'header-center' => __( 'Header Center Navigation', 'imbalance2' ),
'header-right' => __( 'Header Right Navigation', 'imbalance2' ),
'footer-left' => __( 'Footer Left Navigation', 'imbalance2' ),
'footer-right' => __( 'Footer Right Navigation', 'imbalance2' )
) );
}
endif;
/**
* Sets the post excerpt length to 40 characters.
*
* To override this length in a child theme, remove the filter and add your own
* function tied to the excerpt_length filter hook.
*
* #since Twenty Ten 1.0
* #return int
*/
function imbalance2_excerpt_length( $length ) {
return 40;
}
add_filter( 'excerpt_length', 'imbalance2_excerpt_length' );
/**
* Replaces "[...]" (appended to automatically generated excerpts).
*
* To override this in a child theme, remove the filter and add your own
* function tied to the excerpt_more filter hook.
*
* #since Twenty Ten 1.0
* #return string An ellipsis
*/
function imbalance2_auto_excerpt_more( $more ) {
return '';
}
add_filter( 'excerpt_more', 'imbalance2_auto_excerpt_more' );
/**
* Remove inline styles printed when the gallery shortcode is used.
*
* Galleries are styled by the theme in Twenty Ten's style.css. This is just
* a simple filter call that tells WordPress to not use the default styles.
*
* #since Twenty Ten 1.2
*/
add_filter( 'use_default_gallery_style', '__return_false' );
/**
* Deprecated way to remove inline styles printed when the gallery shortcode is used.
*
* This function is no longer needed or used. Use the use_default_gallery_style
* filter instead, as seen above.
*
* #since Twenty Ten 1.0
* #deprecated Deprecated in Twenty Ten 1.2 for WordPress 3.1
*
* #return string The gallery style filter, with the styles themselves removed.
*/
function imbalance2_remove_gallery_css( $css ) {
return preg_replace( "#<style type='text/css'>(.*?)</style>#s", '', $css );
}
// Backwards compatibility with WordPress 3.0.
if ( version_compare( $GLOBALS['wp_version'], '3.1', '<' ) )
add_filter( 'gallery_style', 'imbalance2_remove_gallery_css' );
if ( ! function_exists( 'imbalance2_comment' ) ) :
/**
* Template for comments and pingbacks.
*
* To override this walker in a child theme without modifying the comments template
* simply create your own imbalance2_comment(), and that function will be used instead.
*
* Used as a callback by wp_list_comments() for displaying the comments.
*
* #since Twenty Ten 1.0
*/
function imbalance2_comment( $comment, $args, $depth ) {
$GLOBALS['comment'] = $comment;
switch ( $comment->comment_type ) :
case '' :
?>
<li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
<div id="comment-<?php comment_ID(); ?>">
<div class="comment-avatar">
<?php echo get_avatar( $comment, 60 ); ?>
</div>
<?php if ( $comment->comment_approved == '0' ) : ?>
<em class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.', 'imbalance2' ); ?></em>
<br />
<?php endif; ?>
<div class="comment-author">
<?php printf( __( '%s', 'imbalance2' ), sprintf( '<cite class="fn">%s</cite>', get_comment_author_link() ) ); ?>
</div>
<div class="comment-meta commentmetadata">
<?php
/* translators: 1: date, 2: time */
printf( __( '%1$s at %2$s', 'imbalance2' ), get_comment_date(), get_comment_time() ); ?><?php edit_comment_link( __( '(Edit)', 'imbalance2' ), ' ' );
?>
</div><!-- .comment-meta .commentmetadata -->
<div class="reply">
<?php comment_reply_link( array_merge( $args, array( 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
</div><!-- .reply -->
<div class="comment-body"><?php comment_text(); ?></div>
</div><!-- #comment-## -->
<?php
break;
case 'pingback' :
case 'trackback' :
?>
<li class="post pingback">
<p><?php _e( 'Pingback:', 'imbalance2' ); ?> <?php comment_author_link(); ?><?php edit_comment_link( __( '(Edit)', 'imbalance2' ), ' ' ); ?></p>
<?php
break;
endswitch;
}
endif;
/**
* Removes the default styles that are packaged with the Recent Comments widget.
*
* To override this in a child theme, remove the filter and optionally add your own
* function tied to the widgets_init action hook.
*
* This function uses a filter (show_recent_comments_widget_style) new in WordPress 3.1
* to remove the default style. Using Twenty Ten 1.2 in WordPress 3.0 will show the styles,
* but they won't have any effect on the widget in default Twenty Ten styling.
*
* #since Twenty Ten 1.0
*/
function imbalance2_remove_recent_comments_style() {
add_filter( 'show_recent_comments_widget_style', '__return_false' );
}
add_action( 'widgets_init', 'imbalance2_remove_recent_comments_style' );
if ( ! function_exists( 'imbalance2_posted_by' ) ) :
function imbalance2_posted_by() {
printf( __( '<span class="meta-sep">By</span> %1$s', 'imbalance2' ),
sprintf( '%3$s',
get_author_posts_url( get_the_author_meta( 'ID' ) ),
sprintf( esc_attr__( 'View all posts by %s', 'imbalance2' ), get_the_author() ),
get_the_author()
)
);
}
endif;
if ( ! function_exists( 'imbalance2_posted_on' ) ) :
function imbalance2_posted_on() {
printf( __( '%1$s', 'imbalance2' ),
sprintf( '<span class="entry-date">%1$s</span>',
get_the_date()
)
);
}
endif;
if ( ! function_exists( 'imbalance2_posted_in' ) ) :
function imbalance2_posted_in() {
if ( is_object_in_taxonomy( get_post_type(), 'category' ) ) {
$posted_in = __( '%1$s', 'imbalance2' );
} else {
$posted_in = __( 'Bookmark the permalink.', 'imbalance2' );
}
printf(
$posted_in,
get_the_category_list( ', ' ),
get_permalink(),
the_title_attribute( 'echo=0' )
);
}
endif;
if ( ! function_exists( 'imbalance2_tags' ) ) :
function imbalance2_tags() {
$tag_list = get_the_tag_list( '', ', ' );
if ( $tag_list ) printf(__( '<div class="entry-tags"><span>Tags:</span> %1$s</div>', 'imbalance2' ), $tag_list );
}
endif;
function wpse_custom_header_setup() {
add_theme_support( 'custom-header', apply_filters( 'wpse_header_args', array(
'width' => 1460,
'height' => 220,
) ) );
}
add_action( 'after_setup_theme', 'wpse_custom_header_setup' );
?>
It is the problem of character encoding while saving your file after editing. It may be due to the file editor or Charset setting in FTP you are using to upload. You need to select UTF-8 character set.
To overcome this issue, follow below instructions:
Create a new file in notepad++ and Copy all the content of the editing file(functions.php) and paste it in this new file.
Click on 'Encoding' menu and select 'Encode in UTF-8' to apply UTF-8 character encoding.
Now, save this file as named 'functions.php' and upload it.
If it doesn't work, you can select 'Force in UTF-8' under 'charset' tab in FTP manger(like FileZilla) you are using.
I have created a plugin for wordpress and I am now working on the settings page in the admin area, how do I include a style sheet which is located
plugins/pluginname/assets/css/bootstrap.min.css
Found the solution here:
https://codex.wordpress.org/Function_Reference/wp_enqueue_style
Load stylesheet only on a plugin's options page
/*
* This example will work at least on WordPress 2.6.3,
* but maybe on older versions too.
*/
add_action( 'admin_init', 'my_plugin_admin_init' );
add_action( 'admin_menu', 'my_plugin_admin_menu' );
function my_plugin_admin_init() {
/* Register our stylesheet. */
wp_register_style( 'myPluginStylesheet', plugins_url('stylesheet.css', __FILE__) );
}
function my_plugin_admin_menu() {
/* Register our plugin page */
$page = add_submenu_page( 'edit.php',
__( 'My Plugin', 'myPlugin' ),
__( 'My Plugin', 'myPlugin' ),
'administrator',
__FILE__,
'my_plugin_manage_menu' );
/* Using registered $page handle to hook stylesheet loading */
add_action( 'admin_print_styles-' . $page, 'my_plugin_admin_styles' );
}
function my_plugin_admin_styles() {
/*
* It will be called only on your plugin admin page, enqueue our stylesheet here
*/
wp_enqueue_style( 'myPluginStylesheet' );
}
function my_plugin_manage_menu() {
/* Output our admin page */
}
I am working on a genesis site where I need to move the standard nav menu to above the header. I'm using the following code in the functions.php file of my child theme:
remove_action( 'genesis_after_header', 'genesis_do_nav' );
add_action( 'genesis_before_header', 'genesis_do_nav' );
It's adding a nav menu before the header, but not removing the one after the header. The "after header" one is correctly placed in the output, so I know I'm using the correct hook on the "remove_action". There is nothing else in my functions.php file that is dealing with the nav other than specifying a menu for the footer and adding the descriptions. Below is all the code in my functions.php file (skipping a large section dealing with column shortcodes):
add_action('genesis_setup','child_theme_setup', 15);
function child_theme_setup() {
//Add Homepage Sidebar
genesis_register_sidebar( array( 'name' =>
'Home Sidebar', 'id' => 'home-sidebar' ) );
//Adds footer widgets
add_theme_support( 'genesis-footer-widgets', 6 );
//Adds Footer Text Replace
remove_action( 'genesis_footer', 'genesis_do_footer' );
remove_action('genesis_footer', 'genesis_footer_markup_open', 5);
remove_action('genesis_footer', 'genesis_footer_markup_close', 15);
add_action( 'genesis_after', 'be_footer' );
}
//Function to replace the footer text and copyright
function be_footer() {
echo '<div id="footer" class="footer"><div class="footer-wrap"><div class="left"><p>© Copyright ' . date('Y') . ' RC Auto |Watrous Media</p></div>';
echo '<div class="right">';
wp_nav_menu( array( 'menu' => 'footer' ) );
echo '</div></div></div>';
}
//Add Menu Descriptions
function be_add_description( $item_output, $item ) {
$description = $item->post_content;
if (' ' !== $description )
return preg_replace( '/(<a.*?>[^<]*?)</', '$1' . '<span>' . $description . '</span><', $item_output);
else
return $item_output;
}
add_filter( 'walker_nav_menu_start_el', 'be_add_description', 10, 2 );
// Use shortcodes in widgets
add_filter( 'widget_text', 'do_shortcode' );
/** Move primary nav menu to before header for mobile support*/
remove_action( 'genesis_after_header', 'genesis_do_nav' );
add_action( 'genesis_before_header', 'genesis_do_nav' );
Here's a screenshot:
The Main menu is the styled one added in a widget as I needed it in the header. The main menu I am planning on using as the responsive mobile menu. Anyone know why the lower nav is not removing?
Thanks for your help.
I also had this issue, adding the following code at the start of the child theme's functions.php file fixed it:
require_once( get_template_directory() . '/lib/init.php' );
You can also move remove_action( 'genesis_after_header', 'genesis_do_nav' ); inside your child_theme_setup() function.
Requiring init.php will ensure that the genesis framework is initialized first, so everything after it in your functions file will be able to reference genesis functions. If you are using the genesis_setup action, you'll need to make sure functions that require the genesis framework for reference are run inside that function.
What action or filter can I use in a Wordpress plugin to dynamically replace the contents (i.e. not the header or footer) of a 404 error page?
Basically I'm looking for a 404 error page equivalent for the_content filter, which will filter the contents of an existing page.
Thank you for your time.
Note: I know I can manually modify the 404 error page for the current theme, but that is not the effect I am trying to achieve.
From this WordPress Answer: How to control output of custom post type without modifying theme?
Plugin file:
<?php
/*
Plugin Name: Plugin 404 Page
Plugin URI: http://stackoverflow.com/questions/14539884
Description: Use the plugin's template file to render a custom 404.php
Author: brasofilo
Author URI: https://wordpress.stackexchange.com/users/12615/brasofilo
Version: 2013.26.01
License: GPLv2
*/
class Universal_Template
{
public function __construct()
{
$this->url = plugins_url( '', __FILE__ );
$this->path = plugin_dir_path( __FILE__ );
add_action( 'init', array( $this, 'init' ) );
}
public function init()
{
add_filter( 'template_include', array( $this, 'template_404' ) );
}
public function template_404( $template )
{
if ( is_404() )
$template = $this->path . '/404.php';
return $template;
}
}
$so_14539884 = new Universal_Template();
And in the plugin folder, a file named 404.php:
<?php
/**
* The template for displaying 404 pages (Not Found).
*
* #package WordPress
* #subpackage Twenty_Twelve
* #since Twenty Twelve 1.0
*/
get_header(); ?>
<div id="primary" class="site-content">
MY 404!
</div><!-- #primary -->
<?php get_footer(); ?>
The solution depends on the content of 404.php file. If this file contains static text, like
_e( 'It seems we can’t find what you’re looking for...', 'twentyeleven' );
you can add your own filter
apply_filters( 'my_404_content', 'Default 404 message' );
and in functions.php (or in plugin)
add_filter( 'my_404_content', 'replace_404_message' );
function replace_404_message($message) {
return 'Error 404 - '.$message;
}
If 404.php uses built-in WP functions to display page content, you should check what filters they are supported.
You might be able to add a the_content filter with a conditional is_404 section:
function content_404($content) {
if (is_404()) {
// do some stuff with $content
}
// no matter what,
return $content;
}
add_filter( 'the_content', 'content_404' );
Note that this does assume that the 404.php page template has a the_content template tag in place.