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/
Related
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"]'); ?>
I am having a problem with a site I am developing with wordpress.
It happened after upgrading to the latest version (4.7)
Anyway. Go to the site www.scientized.com (just dummy content for now), and go the source. At around line 124 you see the tag <style type="text/css" id="wp-custom-css"> and then after some css is loaded.
The thing is, is that this some of my old css code from way early. To make life easier and to isolate the problem I have delete all css in my child themes style.css as well as the custom css in the customizer, and delete jetpack just to be sure. Yet this css is being loaded from somewhere. I have file explored the crap out of my site trying to find where this is located, but couldn't find anything.
I have found that in the wp-includes/theme.php there is this function:
function wp_custom_css_cb() {
$styles = wp_get_custom_css();
if ( $styles || is_customize_preview() ) : ?>
<style type="text/css" id="wp-custom-css">
<?php echo strip_tags( $styles ); // Note that esc_html() cannot be used because `div > span` is not interpreted properly. ?>
</style>
<?php endif;
}
so this wp_get_customer_css() function is calling the old css from somewhere -- I tried to follow the functions back to see where - but my php is not that good and got lost. Does anyone know where this is being loaded from?
I think I need to know where the JetPack custom css location is. I have read it is generated dynamically -- so I am not sure how to go about the problem.
Edit: I dont get the text box in the custom css area in customizer. Where is this text located?
Edit: I dont get the text box in the custom css area in customizer. Where is this text located?
The Additional CSS content is stored in wp_posts database table as a separate record. It's post_type is set to custom_css. To find which post is assigned to the field, you need to look in the option theme_mods_{your theme's slug}.
For example, here is the one from my test Sandbox site which is running the Genesis Sample theme. The post ID is 31, per the key custom_css_post_id.
How do I check my site?
You can go directly into your database via phpMyAdmin and look in the wp_options table. Or...you can do this:
add_action( 'init', 'check_custom_css_post_id_theme_mod' );
function check_custom_css_post_id_theme_mod() {
var_dump( get_theme_mods() );
}
The above code will display the theme mods for your current theme. Note the one that is keyed as 'custom_css_post_id'. That one holds the ID to the post for the CSS.
How to Remove It
To remove a theme mod, you use remove_theme_mod( 'custom_css_post_id' );. See codex for the documentation on this construct. It will remove the binding between the Additional CSS. How? It deletes the sub-option.
Note, it does not delete the post record, meaning you'll have an orphaned record in wp_posts.
The wp-custom-css is loaded from custom css & js
I have a template page I have created myself. On it, I add the header used in the WordPress theme using:
get_header();
However, in it, only on this page, I need to add HTML tag. If I add it after the above code, it is not in the section. I do not want to add it to the theme's header, because, as I explained, I do not need this meta tag on other pages. Also, I do not want to copy the whole header in my template's file, as this is duplicate code and it doesn't seem right to me.
Put the changes in your header.php by using conditional tags.
For example, in your header.php, add something like this:
<?php
if (is_page_template( 'templates/YOUR_PAGE_TEMPLATE.php' ) ):
//Your code goes here
endif;
?>
You can use other conditional tags to suit your needs.
Everytime i try to add a shortcode into my Wordpress site it ends up merely displaying the code i add to the actual page. I've been pasting the code into the "text" area of the content section but still doesnt work.
Even when I paste inside of the header.php file I recieve the same result. For example.
I recently copy pasted the following code in header.php (as instructed by the plugin i downloaded)
<div class="headerslider"> <?php echo do_shortcode('[sp_responsiveslider limit="-1"]'); ?></div>
When I save a reload, I just get [sp_responsiveslider limit="-1"] appear in my website. This happens with all shortcodes i do.
Please help
It seems like the shortcode sp_responsiveslider isn't actually defined. Are you sure the plugin is installed correctly? If the plugin is installed correctly you can test to see if shortcodes are working on your WordPress installation. Paste the following in your functions.php file (add <?php to the first line if it's not already in the file):
function test_shortcodes()
{
return 'Shortcodes are working!';
}
add_shortcode('test_shortcodes', 'test_shortcodes');
This will create a new shortcode in WordPress. To test if shortcodes are working put the text [test_shortcodes] within a post and view the page with the post. When you load the page the shortcode tag should be replaced with "Shortcodes are working!". If this works, there is an issue with the plugin and it's shortcode.
If the test text is not displayed there might be a problem with your WordPress installation.
i am trying to insert a post/page into one of my themes files and it wont display shortcodes or php
i have created a page called home in the wordpress admin-paned and inserted into my code the following:
<div id="home_page"> <!-- echos the content from the page "home" id:43 -->
<?php $home_id = 43;
$home_page = get_page( $home_id );
?>
<?php echo $home_page->post_content; ?>
</div> <!-- end #home_page -->
and non of the shortcodes that i have in the page work.
i installed a php in post or page and tried useing php and it doesnt work.
when i insert
echo do_shortcode('[youtube_sc url=http://www.youtube.com/watch?v=Db3XGpt6nNU]');
directly into the code it works.
does anyone know y this happens?
thank you.
I got an answer in wordpress.stackexchange.com
I Quote:
You need to apply the filter the_content e.g.:
<?php echo apply_filters('the_content',$home_page->post_content); ?>
Also, you don't need custom shortcodes for youtube, just put the URL in the content (but not a hyperlink), and it'll be swapped out for a youtube player at runtime. No plugins or extra code needed thanks to oembed.
Thank You Tom J Nowell
The $home_page->post_content value is the exact post content as stored in the database. Echoing this does not give any of your shortcodes a chance to run.
You should use a "WordPress Loop" to display the content, as this sets things up to allow you to use template tags such as the_title() and the_content() - this will call the processing functions for shortcodes and other functions like wpautop() that "massage" post content for output.
If you don't want to use a Loop, you could output the content using
echo do_shortcode($home_page->post_content);
This will run the post content through the shortcode processor, giving the shortcodes a chance to run.
For more on how WordPress "massages" post content, you can look here: http://codex.wordpress.org/How_WordPress_Processes_Post_Content