WordPress Custom Template - Divi module shortcode displays as text - php

I have written a head navigation using the full-width code module in Divi. It is in my Divi library as a global module and works perfectly with most of my pages, but not the ones that are using my custom templates.
The way I am displaying the module is by using it's shortcode at the bottom of my child theme's header.php right before the closing header tag:
<?php echo do_shortcode('[showmodule id="XXXX"]'); ?>
where XXXX is the actual id. But on the pages using custom templates the module displays as plain text like so:
'[et_pb_section global_module="my modules id"][/et_pb_section]'
I have also tried changing the code to:
echo apply_filters('the_content','[showmodule id="XXXX"]');
however, the same issue occurs.
Any Ideas?

I found a good method for this in a thread in the Divi Support Forum, which this dude also explains in a video:
https://www.youtube.com/watch?v=PJqcfz5NyZs
Once you get the global Module number from the URL when viewing it in the Divi Library, the shortcode syntax to load the global module in php is:
<?php echo do_shortcode('[et_pb_section global_module="###"][/et_pb_section]'); ?>
One drawback is that loading a module through a php template file does not allow it to be editable through the Visual Builder.
So, I made a modification to this so I could have an easier place to edit the global footer by adding it to my site's homepage Divi layout, then adding this snippet in my footer.php template file to load on the rest of the pages:
<?php if ( !is_front_page() ) : ?>
<?php echo do_shortcode('[et_pb_section global_module="2310"][/et_pb_section]'); ?>
<?php endif; ?>
This way I can easily have a client use the Visual Builder on the homepage to edit the global footer, instead of having to find it in the Divi Library, which they would likely forget and takes extra click to get there.

Please try adding this code. It will solve your problem
<?php echo do_shortcode('[showmodule id="my modules id"]'); ?>

Related

How to add plugins to my custom wordpress theme?

I'm making a WordPress theme by myself since I'm working for the first time in Wordpress I've watched some tutorials about it.
I have page.php header and footer and ofc an index. I insert the content from the pages with this:
<?php echo get_post_field('post_content', $post->ID); ?>
but I tried the get_post in a while loop with same result..
Everything is fine but when I want to use a plugin I can't add to my page... When I insert the shortcode of it it shows only the shortcode string... There are some plugins where I can click a "view" option and it would show a page with my plugin (for example a calendar) but that page is empty...
When I activate an original theme it works instantly... So I'm sure something is missing from my theme something which can load the plugins but I couldn't find solution for it.
Any ideas?
Did you add the <?php wp_head(); ?> function before the head area of the html document is closing? It imports important scripts and styles from wordpress itself (and probably also from the plugins).
See here:
https://developer.wordpress.org/reference/functions/wp_head/
Before closing the body area, the template should also include
<?php wp_footer();?>
See here:
https://developer.wordpress.org/reference/functions/wp_footer/

How to implement Visual Composer VC Codes to the Wordpress Homepage php Template?

I am working with a WordPress site. I used Fancy Text element of the Visual composer in a post. But I want to show this on Homepage. And for homepage, I already get the Homepage template which I have used. I made a custom section with post of this Fancy text. But Homepage is in PHP language. So, my VC_Column and VC_Rows codes are not working on the homepage.
I have tried using
< ?php echo do_shortcode(“ ”); ? >
But I'm noob. Unable to use this also. and only the code is visible on the homepage.
Please tell me how I can use Visual Composer on PHP so that I can edit my homepage template of the theme.
Thank you.
WordPress shortcodes provide you extra functionality and allow you to embed content into pages. do_shortcode, which you can use to add shortcodes to any part of your site.
https://developer.wordpress.org/reference/functions/do_shortcode/
The visual composer plugin feature can use with a short code within the page template.
<?php
$content = 'test content';
//number of vc_column you have a need to use, according to your requirement.
echo do_shortcode( '[vc_row][vc_column width="1/1"]'.$content.'[/vc_column][/vc_row]' );
?>
You can try.
<?php
$array_ultimate_fancytext = array("fancytext_strings1" =>'[ultimate_fancytext strings_textspeed="35" strings_backspeed="0" fancytext_strings="Welcome Namaste Wellkumma Шъукъеблагъ iHola! Shagotom आईं ना Tusanyuse okubalaba" strings_font_size="desktop:60px;"]',
"fancytext_strings2"=>'[cq_vc_cqbutton buttonlabel="Kidney Transplant" link="url:http%3A%2F%2Fwww.yourmedicament.com%2Fdoctors%2Fdr-abhay-kumar%2F|title:Dr.%20Abhay%20Kumar||"]');
foreach($array_ultimate_fancytext as $value){
$content = do_shortcode($value);
echo do_shortcode('[vc_row][vc_column]'.$content .'[/vc_column][/vc_row]' );
}
?>

How to edit the html code in wordpress theme

I have a wordpress blog and I want to customize it a bit. I know CSS and HTML but not php. from what I understood the php should call the html code, so if i could find the html code it will be easy for me to customize my blog.
The thing is, I can't find the html code. I looked at appearance --> editor and it is all php files and one css.
Someone has an idea how to edit the html code/find it ?
thanks
If you want to edit your wordpress theme html , css etc. Kindly follow the steps.
Always use a child theme
Before you start editing your WordPress theme create a child theme. Child themes are important, because they protect your original theme files.
Appearance → Themes->your child theme-> activate
Edit WordPress theme HTML
Go to Appearance → Editor in your WordPress dashboard and choose the child theme you have activated.
There are index.php, functions.php, header.php, footer.php etc.
In its most basic form, PHP is grabbing content from your WordPress site and outputting it in an HTML page. Take a look at this section of code specifically:
<div class="site-info">
<?php do_action( 'twentyfourteen_credits' ); ?>
<?php printf( __( 'Proudly powered by %s', 'twentyfourteen' ), 'WordPress' ); ?>
</div><!-- .site-info -->
That code translates to this HTML:
<div class="site-info">
Proudly powered by WordPress
</div><!-- .site-info -->
Try to understand like the above codes php and html. you can easily edit it.
Edit WordPress theme CSS
Appearance → Editor->style.css(child theme).
you can change the style of detailed reference click here
Go to your wp-admin, Appearance (on the left sidebar), Editor. Select a theme and a file to edit, then press Save.
In WordPress Dashboard > Appeareance > Editor you can't edit HTML files (only PHP and CSS files) as you can read in Codex - "Editing files"
Your question could become why don't you see HTML in PHP files?
This is because PHP generates HTML code and then you can see lots of PHP code inside a PHP file, but not necessarly HTML code. In order to understand how PHP works I suggest you to read this useful tutorial.

Custom template or theme (header and footer) for PDP page in Magento

We're redoing our theme in Magento to use a grid system (semantic.gs), and I've been tasked with the duty setting up the PDP page to use this new grid system template. We eventually will want this template on all pages, but for now, it's been specifically requested ONLY on the PDP page. So basically I want to set a custom theme/template (including header and footer, not just columns) that I can load on certain pages. Can anyone point me in the direction of how to go about doing this? Extensive SO and google searching has come up pretty fruitless.
So far:
I created a new layout called 2columns-left-grid.phtml in app/design/frontend/[my_interface]/[my_theme]/template/page
I modified these lines:
<?php echo $this->getChildHtml('header') ?>
and
<?php echo $this->getChildHtml('footer') ?>
To be:
<?php echo $this->getChildHtml('header2') ?>
and
<?php echo $this->getChildHtml('footer2') ?>
I duplicated header.phtml and named it header2.phtml, and duplicated footer.phtml and named it footer2.html
My questions:
Will this work, and if so, what other code do I need to modify (xml files, etc)
How can I get this template to apply ONLY to the PDP page for now?
Thanks!
Hello you can override product tag
< catalog_product_view translate="label">
/app/design/frontend/base/default/layout/catalog.xml
from into your new module layout xml

Include wordpress theme in a custom php page

I need to include a custom PHP page in Wordpress.
So what I need to do is just to show this custom php page using the Wordpress theme installed on that Wordpress.
Does not mind which theme is up, the custom php page will have to be shown under any theme is installed in that moment.
How do I do it in Wordpress?
I am new to Wordpress development.
Thanks
Creating a custom php page that will be able to be viewed in any theme (and have the theme applied) would be considerably difficult.
Each wordpress page calls specific theme functions of that particular theme, as well as referencing files of that theme to generate header, footer, css files, javascript files, etc.. Your custom page would need to plan for all of these contingencies, for each possible theme used.
Here's a alternative solution: inject PHP code directly into a standard wordpress page via this plugin http://wordpress.org/extend/plugins/allow-php-in-posts-and-pages/
Meaning: you make a normal wordpress page, but are able to add php to it. When this page is rendered, the proper page template is used, and all the theme references are taken care of for you.
You could do this easily with a page template. WordPress allows you to create page templates which can be assigned to a page via the 'Page Attributes' panel within the page editor. These templates are php files inside your theme directory which begin with some code like (see this page in The Codex for more info):
<?php
/*
Template name: Custom PHP Page
*/
?>
<?php // begin custom PHP page ?>
Typically a template is a variation on the regular theme files (such as page.php) and would call the get_header() and get_footer() functions and have an instance of the loop. However if you simply want to use a custom PHP page, then all you need to do is create the file you want inside the current theme directory and add the above code at the very top of the file.
To output the custom PHP page on your site, you would need to add a new page via the admin area and then assign your new page template to this page.
Alternatively, if you want to include a custom PHP page inside an existing theme file, you use the code:
<?php include(TEMPLATEPATH . '/includes/file.php'); ?>
in this case your custom PHP file would be located inside a directory called 'includes' within your current theme directory.
Tim.
It's not that difficult. Here's what you need:
Once you include the main wordpress blog header, the entire armamentarium of wordpress functions is available to you, which allows you to get the active theme's directory. Once you get that, just include the header and the footer of the theme.
// If title is not displayed before loading the header, Wordpress displays "Page not found" as the title
echo "<head>
<title>Your page title</title>
</head>";
// Include the Main Wordpress blog header
include $_SERVER['DOCUMENT_ROOT']."/wp-blog-header.php";
//Now, you need to get the active theme's folder, and get a relative path to that folder
$homeurl=home_url();
$ddir= get_bloginfo( 'template_directory');
$current_theme_relative_path=substr_replace($ddir, "", 0, strlen($homeurl));
//echo "<br/>The relative path to the currently active theme is ".$current_theme_relative_path;
//Once you have the path, include the header and footer, adding your custom php code in between.
// Include the specific theme header you need
include $_SERVER['DOCUMENT_ROOT'].$current_theme_relative_path."/header.php";
// Your custom PHP code STARTS here
// Add anything you want to display to the user
echo "
<h2>
Your form has been submitted
</h2>";
// END of custom code
?>
<?php
}
// Now end with the theme's footer
include $_SERVER['DOCUMENT_ROOT'].$current_theme_relative_path."/footer.php";
?>
Was very helpfull (even if dated of 2011-13)
Also, as a thank you, i'm sharing the version i made
it's usefull if your wordpress folder is not located at ROOT
PasBin Link - wordpress custom php page
just change the value of $wplocalpath in :
// Wordpress path (if wordpress is not located at ROOT
// $wplocalpath="/Wordpress1";

Categories