Custom excerpt for child template on Wordpress - php

I've been creating a child Wordrpess theme. The parent theme is TwentyTwelve theme.
I override styles.css file and it works perfectly. But I can't replace the_excerpt function on my functions.php
I've been searching but I can't find the solution.
functions.php
<?php
function custom_excerpt($text) {
return "Test";
}
function my_child_theme_setup() {
add_filter('the_excerpt', 'custom_excerpt');
add_filter('get_the_excerpt', 'custom_excerpt');
add_filter('default_excerpt', 'custom_excerpt');
}
add_action( 'after_setup_theme', 'my_child_theme_setup' );
?>
I just wan't to show the featured image on the excerpt linking the original post.
Thanks!

Related

Execute a shortcode inside a folder in a Child Theme

I'm confused on how to run my custom shortcode in my child theme. To my understanding, I should be only including/requiring the file in the functions.php in my child theme right?
My File Structure is like this
**Child Theme**
-functions.php
-deals
--deals.php
In my functions.php i just place the code
require_once('deals/deals.php' );
And in my deals.php, I have this shortcode
add_shortcode('show-deals','show_deals');
function show_deals() {
return 'Show Deals';
}
So it doesn't get rendered. Help

How to Disable Changing the Installed Theme in Wordpress?

I developed my own WordPress theme for my client!.
If he changes the theme from outside, he will lose my theme.
I want to disable him from changing Wordpress theme from mine theme.
How can I Disable it? is there any way by editing the Wordpress files?
You can remove theme submenu using following code. Add below code in your theme's functions.php file.
add_action( 'admin_menu', 'adjust_the_wp_menu', 999 );
function adjust_the_wp_menu()
{
remove_submenu_page( 'themes.php', 'themes.php' );
}
Restrict admin to open file
add_action( 'current_screen', 'this_screen' );
function this_screen()
{
$current_screen = get_current_screen();
if( $current_screen ->id === "themes" )
{
wp_die("You don't have access to this page.");
}
}

Replacing Woocommerce Storefront header with a shortcode

I am using Woocommerce Storefront theme and I want to replace the original header with a custom header that I created in elementor. I have a shortcode for the new header but I don't know how to insert it into the code. I am using a blank storefront child theme and there is a function.php file and style.css file.
Thanks for the help.
Just copy the header.php from the parent theme and paste it inside the child theme. Then you can already put your custom code in it.
Reference: codex.wordpress.org/Child_Themes
You can do this in your child theme by using a hook on init
Something like this:
add_action('init', 'replace_header' );
function replace_header(){
remove_action( 'storefront_header', 'storefront_primary_navigation', 50 );
add_action('storefront_header', 'my_custom_header', 50);
}
function my_custom_header(){
do_shortecode('[your_elementor_header_shortcode attr1="value1"]')
}

How to place content from function in My Account in Woocommerce?

Hi i have this function inserted into functions.php in my theme:
function woocommerce_after_account_navigation(){
$html = '<h3>Title</h3>';
$html.='<li>Text1</li>';
$html.='<li>Text2</li>';
echo $html;
}
and have placed this hook into navigation.php file from WooCommerce templates
<?php do_action( 'woocommerce_after_account_navigation' ); ?>
but seems that dont show nothing from content that i placed into functions.php
Can someone help me what is wrong with this hook ?
Youn don't need to change anything in the My account templates (as you are using an existing hook)… To get your custom content displayed, you should need to make it this way:
add_action( 'woocommerce_after_account_navigation', 'custom_content_after_account_navigation' );
function custom_content_after_account_navigation(){
$html = '<h3>Title</h3>';
$html.='<li>Text1</li>';
$html.='<li>Text2</li>';
echo $html;
}
Code goes in function.php file of your active child theme (or theme) or also in any plugin file.
Tested on WooCommerce 3 and works.
This custom content will be displayed below the My Account Menu

how to add enfold theme shortcode to my wordpress theme

I'm developing a new theme for a site which is using endfold at the moment
Now, i have a problem with previous posts that have used enfold's shortcode and my theme doesn't support them how can I add enfold's shortcode to my theme
Shortcodes in Wordpress are defined likes this:
//[foobar]
function foobar_func( $atts ){
return "foo and bar";
}
add_shortcode( 'foobar', 'foobar_func' );
https://codex.wordpress.org/Shortcode_API
You have to find the defined shortcut in the endfold theme files (just grep for the shortcode alias) and reimplement this code on your theme.

Categories