Creating custom credits using add_filter - php

As far as I understand I can use add_filter('hook', 'my_custom_credits'); to replace default credits with a custom one. I know how to create my_custom_credits function and it's working.
But I'm not sure how to find hook in someone's code. Do I need to create it or I just use some id?
<?php
/**
* The template for displaying the footer credits
*
*/
?>
<div id="footer__credits" class="footer__credits" <?php czr_fn_echo('element_attributes') ?>>
<p class="czr-copyright">
<span class="czr-copyright-text">© <?php echo esc_attr( date('Y') ) ?> </span><a class="czr-copyright-link" href="<?php echo esc_url( home_url() ) ?>" title="<?php echo esc_attr( get_bloginfo() ) ?>"><?php echo esc_attr( get_bloginfo() ) ?></a><span class="czr-rights-text"> – <?php _e( 'All rights reserved', 'customizr') ?></span>
</p>
<p class="czr-credits">
<span class="czr-designer">
<span class="czr-wp-powered"><span class="czr-wp-powered-text"><?php _e( 'Powered by', 'customizr') ?> </span><a class="czr-wp-powered-link fab fa-wordpress" title="<?php _e( 'Powered by WordPress', 'customizr' ) ?>" href="<?php echo esc_url( __( 'https://wordpress.org/', 'customizr' ) ); ?>" target="_blank"></a></span><span class="czr-designer-text"> – <?php printf( __('Designed with the %s', 'customizr'), sprintf( '<a class="czr-designer-link" href="%1$s" title="%2$s">%2$s</a>', esc_url( CZR_WEBSITE . 'customizr' ), __('Customizr theme', 'customizr') ) ); ?></span>
</span>
</p>
</div>

Related

the difference between using esc_html and esc_attr in wordpress

I look at this example:
esc_html would be used inside of html for example between a <p> tag
<p><?php echo esc_html( $some_variable ); ?></p>
esc_attr would be used for escaping attribute values on html tags like so:
<p my-attribute="<?php echo esc_attr( $some_variable ); ?>"></p>
And I can't apply it to my code, am I doing it right?
Can anyone elaborate/explain with my live example what shielding is needed and why.
I'd be happy to get any answers on this case:
1. echo '<div class="bg-primary ' . esc_attr( $theme-name_header_class ) . '" id="subheader">';
<a href="<?php echo esc_url( $theme-name_l['url'] ); ?>" class="<?php if ( $theme-name_l['active'] ) { echo 'current-lng'; } ?> inline-flex">
<?php echo esc_html( $theme-name_l['language_code'] ); ?>
</a>
2. <a href="/<?php echo esc_attr( $theme-name_lng ); ?>/" class="<?php if ( $theme-name_current_uri === $theme-name_lng ) { echo 'current-lng'; } ?> inline-flex items-center text-xs lg:text-base h-5 pl-2 pr-3 leading-none text-accent border-accent capitalize" aria-label="<?php echo esc_attr( $theme-name_lng ); ?>" >
<?php echo esc_html( $theme-name_lng ); ?>
</a>
3. <div class="item-content-mega__desc">
<?php echo esc_html( $theme-name_children_post_desc ); ?>
</div>
4. <a class="px-4" href="<?php echo esc_url( $theme-name_parent_post_url ); ?>" aria-label="<?php echo esc_attr( $theme-name_parent_post_title ); ?>" class="transition-colors <?php if ( $theme-name_parent_post_url === $theme-name_current_url ) { echo 'active'; } ?>">
<span class="capitalize"><?php echo esc_attr( ucfirst( strtolower( $theme-name_parent_post_title ) ) ); ?></span>
</a>

Change my custom logo 'home destination' in Wordpress

header.php question here. I have a custom logo being used on a specific set of listings pages https://carolroyseteam.com/our-nice-home/ , I've assigned it using a body class assignment to swap the header $logo in the header.php. Then the rest of the site with the branding of the domain https://carolroyseteam.com/. Is there anything that can be done to assign a different url to the two $logo's?
To clarify my custom logo for Our Nice homes logo goes to '/our-nice-home/' and then have standard domain home logo link to the default logo cotainer ">
Using Divi Theme
<?php ob_start(); ?>
<header id="main-header" data-height-onload="<?php echo esc_attr( et_get_option( 'menu_height', '66' ) ); ?>">
<div class="container clearfix et_menu_container">
<?php
$logo = ( $user_logo = et_get_option( 'divi_logo' ) ) && ! empty( $user_logo )
? $user_logo
: $template_directory_uri . '/images/logo.png';
ob_start();
?>
<?php
$classes = get_body_class();
if (in_array('ournicehomeslogo',$classes)) {
$logo="/wp-content/uploads/2019/10/1-ONH-Logo-05-carolroyseteam.png";}
?>
<?php
$classes = get_body_class();
if (in_array('single-listing',$classes)) {
$logo="/wp-content/uploads/2019/10/1-ONH-Logo-05-carolroyseteam.png";}
?>
<?php
$classes = get_body_class();
if (in_array('search-results',$classes)) {
$logo="/wp-content/uploads/2019/10/1-ONH-Logo-05-carolroyseteam.png";}
?>
<div class="logo_container">
<span class="logo_helper"></span>
<a href="/our-nice-homes/">
<img src="<?php echo esc_attr( $logo ); ?>" alt="<?php echo esc_attr( get_bloginfo( 'name' ) ); ?>" id="logo" data-height-percentage="<?php echo esc_attr( et_get_option( 'logo_height', '54' ) ); ?>" />
</a>
</div>
<?php
$logo_container = ob_get_clean();
Got it! Wordpress Divi Theme users will appreciate that this logo_container is a default in the header.php file. This has been the easiest way to both custom logo a specific page or pages and then modify the home url.
<div class="logo_container">
<span class="logo_helper"></span>
<a href="<?php $classes = get_body_class();
if (in_array('ournicehomeslogo',$classes)) {
echo esc_url( home_url( '/our-nice-homes/' ) );}
else if (in_array('single-listing',$classes)) {
echo esc_url( home_url( '/our-nice-homes/' ) );}
else if (in_array('search-results',$classes)) {
echo esc_url( home_url( '/our-nice-homes/' ) );}
else{
echo esc_url( home_url( '/' ) );
} ?>">
<img src="<?php echo esc_attr( $logo ); ?>" alt="<?php echo esc_attr( get_bloginfo( 'name' ) ); ?>" id="logo" data-height-percentage="<?php echo esc_attr( et_get_option( 'logo_height', '54' ) ); ?>" />
</a>
</div>
<?php
$logo_container = ob_get_clean();

How do I add social sharing buttons?

I am on Wordpress and I can easily add a plugin, but that increases load time, looks common and old.
I am using the Brook theme, which a minimal theme. (http://www.defensionem.com/7th-and-3rd-fleet-to-be-combined/)
If you notice, only end at the blog I have my sharing options, Such as Facebook, Linkedin, Twitter.
Can I enable this in the Sidebar widget? I contacted my theme author and they said to me,
"Our social-sharing links are built in brook/share_block.php. You
could try creating a new custom widget, and use the code from
share_block.php. Alternatively, you could use a Text Widget, and input
directly html code for sharing. By using the markup and classes as we
did, you should be able to get the same style."
Here's my that php file. I tried various methods but it did not work. Guess everything is wrong.
Can you all help?
<?php
$theme_settings = brook_theme_settings();
if( has_post_thumbnail() ){
$share_image = wp_get_attachment_image_src( get_post_thumbnail_id(), 'xxl' );
$share_image = $share_image[0];
$share_image_portrait = wp_get_attachment_image_src( get_post_thumbnail_id(), 'portrait-m' );
$share_image_portrait = $share_image_portrait[0];
}else{
$share_image = '';
$share_image_portrait = '';
}
$share_excerpt = strip_tags( get_the_excerpt(), '<b><i><strong><a>' );
?>
<div class="social-nav social-nav--titles">
<ul class="social-nav__items">
<?php if( $theme_settings['sharing_email'] ): ?>
<li class="social-nav__item">
<a title="<?php _e( 'Email', 'brook' ); ?>" class="social-nav__link js-skip-ajax" href="mailto:?subject=<?php echo ( rawurlencode( get_the_title() ) ); ?>&body=<?php echo ( rawurlencode ( $share_excerpt . ' ' . get_the_permalink() ) ); ?>">
<?php _e( 'Email', 'brook' ); ?>
</a>
</li>
<?php endif; ?>
<?php if( $theme_settings['sharing_facebook'] ): ?>
<li class="social-nav__item">
<a title="<?php _e( 'Facebook', 'brook' ); ?>" class="social-nav__link js-sharer js-skip-ajax" target="_blank" href="http://www.facebook.com/sharer.php?u=<?php echo( rawurlencode( get_the_permalink() ) ); ?>">
<?php _e( 'Facebook', 'brook' ); ?>
</a>
</li>
<?php endif; ?>
<?php if( $theme_settings['sharing_twitter'] ): ?>
<li class="social-nav__item">
<a title="<?php _e( 'Twitter', 'brook' ); ?>" class="social-nav__link js-sharer js-skip-ajax" target="_blank" href="http://twitter.com/intent/tweet?text=<?php echo( rawurlencode( get_the_title() ) ); ?>&url=<?php echo( rawurlencode( get_the_permalink() ) ); ?>">
<?php _e( 'Twitter', 'brook' ); ?>
</a>
</li>
<?php endif; ?>
<?php if( $theme_settings['sharing_pinterest'] ): ?>
<li class="social-nav__item">
<a title="<?php _e( 'Pinterest', 'brook' ); ?>" class="social-nav__link js-sharer js-skip-ajax" target="_blank" href="http://pinterest.com/pin/create/button/?url=<?php echo( rawurlencode( get_the_permalink() ) ); ?>&media=<?php echo ( rawurlencode( $share_image_portrait ) ); ?>&description=<?php echo( rawurlencode( get_the_title() ) ); ?>">
<?php _e( 'Pinterest', 'brook' ); ?>
</a>
</li>
<?php endif; ?>
<?php if( $theme_settings['sharing_google'] ): ?>
<li class="social-nav__item">
<a title="<?php _e( 'Google+', 'brook' ); ?>" class="social-nav__link js-sharer js-skip-ajax" target="_blank" href="https://plus.google.com/share?url=<?php echo( rawurlencode( get_the_permalink() ) ); ?>">
<?php _e( 'Google+', 'brook' ); ?>
</a>
</li>
<?php endif; ?>
<?php if( $theme_settings['sharing_linkedin'] ): ?>
<li class="social-nav__item">
<a title="<?php _e( 'LinkedIn', 'brook' ); ?>" class="social-nav__link js-sharer js-skip-ajax" target="_blank" href="http://www.linkedin.com/shareArticle?mini=true&url=<?php echo( rawurlencode( get_the_permalink() ) ); ?>&title=<?php echo( rawurlencode( get_the_title() ) ); ?>&summary=<?php echo ( rawurlencode ( $share_excerpt ) );?>&source=<?php echo ( rawurlencode( get_bloginfo('name') ) );?>">
<?php _e( 'LinkedIn', 'brook' ); ?>
</a>
</li>
<?php endif; ?>
</ul>
</div>
Well What I suggest you which is the easiest solution is first install a plugin from this link https://wordpress.org/plugins/php-code-widget/ It ia a plugin when you activate it, it creates a widget in which you can put your all php code from your required file. As far as the styling is concerned you can add the relevant styling to main css file of your Brook theme. I hope it helps....
Try to social share plugin and put shortcode.

woocommerce code for cart button

I need to add the woocommerce cart button to one of my pages and was wondering if someone could help with the code required to call the cart button. Here is the current code:
<?php woocommerce_product_loop_start(); ?>
<?php woocommerce_product_subcategories(); ?>
<?php while ( have_posts() ) : the_post(); ?>
<div id="product-image1">
<a href="<?php echo esc_url( get_permalink( $product->id ) ); ?>" title="<?php echo esc_attr( $product->get_title() ); ?>">
<?php echo $product->get_image(); ?>
</a>
</div>
<div id="product-description-container">
<ul>
<a href="<?php echo esc_url( get_permalink( $product->id ) ); ?>" title="<?php echo esc_attr( $product->get_title() ); ?>">
<li><h4><?php echo $product->get_title(); ?></h4></li></a>
<li><?php echo apply_filters( 'woocommerce_short_description', $post->post_excerpt )?></li>
<li><h6><?php echo $product->get_price_html(); ?> **MISSING CODE TO ADD TO CART BUTTON HERE**</h6></li>
</ul>
</div>
<?php endwhile; // end of the loop. ?>
I think may be you need following code.
Add this code to your place = (**MISSING CODE TO ADD TO CART BUTTON HERE**).
global $product;
echo apply_filters( 'woocommerce_loop_add_to_cart_link',
sprintf( '%s',
esc_url( $product->add_to_cart_url() ),
esc_attr( $product->get_id() ),
esc_attr( $product->get_sku() ),
$product->is_purchasable() ? 'add_to_cart_button' : '',
esc_attr( $product->get_type() ),
esc_html( $product->add_to_cart_text() )
),
$product );
Hope this will help.

change header top banner content on specific page

I have a static top banner inside my header.php file build like this :
<div class="row-fluid top-banner">
<div class="container">
<div class="banner-overlay"></div>
<?php
$logo = of_get_option('logo', '' );
if ( !empty( $logo ) ) { ?>
<a class="brand brand-image" href="<?php echo esc_url( home_url( '/' ) ); ?>" title="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>" rel="home"><img src="<?php echo $logo; ?>" alt="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>"><h1><?php if(!of_get_option('disable_description')){ ?><small><?php bloginfo( 'description' ); ?></small><?php } ?></h1></a>
<?php }else{ ?>
<a class="brand brand-text" href="<?php echo home_url( '/' ); ?>" title="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>" rel="home"><h1><?php bloginfo( 'name' ); ?><?php if(!of_get_option('disable_description')){ ?><small><?php bloginfo( 'description' ); ?></small><?php } ?></h1></a>
<?php }
if(of_get_option('disable_description')){ $top_banner_fix = 'style="top:15px;"'; }else{ $top_banner_fix = ''; }
?>
</div>
</div>
What I want to do is to change top-banner div content on a specific page, in my case the contact page which is created from the dashboard is not a template page.
So, I'm thinking to use the conditional tag :<?php is_page($page); ?>
The problem is that I'm not sure how to use this function. Is it possible to just add some markup inside the div and it will overwrite the existing one ?
Can you please give me some indications on how can I do this ?
Thank you!
is_page is a boolean function, so it's as easy as a new if else clause:
<div class="row-fluid top-banner">
<div class="container">
<div class="banner-overlay"></div>
<?php
$logo = of_get_option('logo', '' );
if (is_page($contactPage)) {
/*PUT STATIC CONTENT HERE*/
} else if ( !empty( $logo ) ) { ?>
<a class="brand brand-image" href="<?php echo esc_url( home_url( '/' ) ); ?>" title="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>" rel="home"><img src="<?php echo $logo; ?>" alt="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>"><h1><?php if(!of_get_option('disable_description')){ ?><small><?php bloginfo( 'description' ); ?></small><?php } ?></h1></a>
<?php }else{ ?>
<a class="brand brand-text" href="<?php echo home_url( '/' ); ?>" title="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>" rel="home"><h1><?php bloginfo( 'name' ); ?><?php if(!of_get_option('disable_description')){ ?><small><?php bloginfo( 'description' ); ?></small><?php } ?></h1></a>
<?php }
if(of_get_option('disable_description')){ $top_banner_fix = 'style="top:15px;"'; }
else{ $top_banner_fix = ''; }
?>
</div>
</div>
For $contactpage: when you are logged in into your Wordpress admin site, go to the frontend. Then go to the contact page (the one you want to have this new content on). Click on edit in the top banner. Look at the link. (You can also get there via the dashboard).
The link will look a bit like this: post.php?post=280&action=edit
That number, 280 in this case, is the ID of the page. You can use that for $contactPage:
if (is_page(280)) { /*...*/ }
Hope this helps :)
For different banner on all pages and posts you can use Attachment Plugin and then have to create instance for that in function.php file. then you can see that attachment metabox in all pages and post form page in admin panel.
Try this and let me know if any further help required.
Thanks!

Categories