Embedded Wordpress form plugin shortcode not displaying in page - wordpress

I currently creating a Wordpress custom theme with the Ninja Forms plugin, for one of the pages Ive embedded the Ninja Form using the shortcode such as [ninja_form id=2] and Ive inserted the post directly into the inner page as such
$id = $_GET['page_id'];
$post = get_post($id, 'OBJECT', 'display');
//display the post
echo '<h1 class="dark">'.$post->post_title.'</h1>';
echo $post->post_content;
But the embedded form shortcode doesnt resolve to actually load the form into the page. What Im not doing??

try checking your Javascript files and CSS files that it doesn't affect the plugin you are using, because some of javascripts and JQueries overrides on the plugins you are using.

Related

Can Shortcodes be used in a Static WordPress Homepage?

I have a Static page set as the home page of my wordpress website. It has a custom shortcode to show a woocommerce catalog based on my own meta query.
When I add valid products, it does not show up immediately or even after a while. However, if I publish the static page, then it shows up magically, thus leading to my question.
What are my alternatives, if I want to show my shortcode on a static home page?
I think this is my problem and nothing else, because I tried disabling all plugins and clearing the cache, but still it did not show the latest added products.
You can edit the template of your theme adding the do_shortcode() function where you want the shortcode to be displayed, for example:
<?php echo do_shortcode( '[contact-form-7 id="91" title="quote"]' ); ?>

Is there some way to insert custom archive loop to any theme from plugin?

I'm coding plugin that create custom post type with custom fields. Now I need to build custom archive/category/tag templates which should contain custom fields.
The problem is that I couldn't insert template part inside archive loop from plugin.
Is there some hook to insert custom loop inside activated theme? Something like this:
add_filter('the_content', 'change_content_in_single_post');
Now I'm using this hook:
add_filter( 'template_include', 'change_whole_cpt_archive_template' );
... but when I use template_include hook it changes whole template and I need to do something like the_content filter. That hook get template of current theme and replace standart content template with my custom template - make it part of activated theme. It makes my CPT single page template compatible with any wp theme. Now I need to replace standart archive loop with my custom loop. For example: on archive page show posts without images... It must be something that replace result of standard get_template_part() function with custom template from plugin. That's what I`m searching for...
Anyway, maybe you know some better ways to make plugin (archive template) compatible with wp themes?
Huge thanks for any help!
you need to introduce some logic to only run on your cpt archive page.
add_filter( 'template_include', 'change_all_archive_template' );
function change_all_archive_template($template){
if ( is_post_type_archive('cptname') ) {
$template= 'find the template!';
//if( file_exists ) --> look in theme 1st??
//else --> load from plugin..
}
return $template;
}
There are quite a few plugins that use this technique to look in the active theme 1st and if not found, find the file in your plugin.
I found solution in woocommerce plugin files.
So... the best way to build custom archive template from plugin is to use template_include hook and in custom template file set header and footer from activated theme:
<?php get_header();
// custom archive loop
get_footer(); ?>
To make it more compatible with any wp themes use stanard wordpress and bootstrap classes.

WP the_content display plugins attachments only

This might be a silly question since I'm new to wp but i'm trying to create a custom post feed.
Basically i have this loop
while ( have_posts() ){
the_post();
the_title();
the_post_thumbnail('content-thumb');
//and here i have installed facebook share plugin
//so if i put the_content() it would display share button
//the problem is it also display post text and everything else while i only
//need that plugin button or whatever comes with that plugin
}
The Facebook share plugin is most probably hooking the button code to the_content filter hook. The only way to avoid both 'the content' and the 'facebook button' from both displaying at once is to unhook the button from the_content using remove_filter() and then add the button manually to the page.
Read more about WordPress hooks in the Plugin API/Hooks article.
Refs:
http://codex.wordpress.org/Plugin_API/Filter_Reference/the_content
http://codex.wordpress.org/Function_Reference/remove_filter

Wordpress plugin shortscodes in other plugins?

I'm developing a plugin that creates custom wordpress pages, however I ran into a problem when trying to get shortcodes from other plugins to integrate into my plugin, well more like I couldn't find any info on it.
For example if someone uses my custom page builder and adds a short code [gallery] that is associated with an enabled plugin, I want the shortcode to do it's thing.
Could anyone point me in the right direction for this?
Try wordpress
http://wordpress.org/plugins/synved-shortcodes/
while this plugin let's you integrate shortcodes on every wordpress page , I suppose that you issue is with wordpress functions.php file where you can have a look at , with this plugin installed !
You can check if a shortcode exist before printing it with the function shortcode_exists() (https://codex.wordpress.org/Function_Reference/shortcode_exists)
Example:
<?php
if ( shortcode_exists( 'gallery' ) ) {
// The [gallery] short code exists.
}
?>
Then, if it exist and you want to print that shortcode with PHP code you should use do_shortcode() function (https://developer.wordpress.org/reference/functions/do_shortcode/)
Example:
<?php echo do_shortcode('[gallery]); ?>
Always use in WordPress's in-built
the_content
hook to print your custom page content.
WordPress by default process all shortcodes before outputting any stuff from this hook.
More info can be found here: https://codex.wordpress.org/Function_Reference/the_content

Shortcode not parsing in page template - Wordpress

I've created a 404 error page in Wordpress and am trying include a contact form in the 404.php template. So, I've installed the "Fast secure contact form" plugin and have created a post that includes the shortcode for said plugin. When I view the post for this plugin the contact form shows properly. When I try to manually inject the post into the 404.php template using:
$page_id = 4015;
$page_object = get_post( $page_id );
echo $page_object->post_content;
The shortcode just displays as text. Any help with this would be greatly appreciated ...
Why not do it like this, add the shortcode to your 404 page.
<?php echo do_shortcode('[si-contact-form form="1"]'); ?>
You need not have to create a new post for the contact form.

Resources