• Resolved bluegum

    (@bluegum)


    I am trying make the shortcodes work, but it isn’t working. What I am really trying to do is to create a functions.php file with shortcodes, then place the shortcodes into a page via the Add New Page.

    One of the shortcodes in the functions.php:

    function contactus($atts) {
    	 extract(shortcode_atts(array(
    		$contactus_page_post_id = 26,
    		$contactus_page_post = get_post($contactus_page_post_id, ARRAY_A),
    		$content_contactus = $contactus_page_post['post_content'],
    	 ), $atts));
    
    		return $content_contactus;
    }
    
    add_shortcode('contact', 'contactus');

    With the actual shortcode like this: [contactus=”contact”]. Can someone please tell me how I can make the shortcodes work? Thanks in advance.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter bluegum

    (@bluegum)

    Please someone help me with this.

    Thread Starter bluegum

    (@bluegum)

    I have finally worked out why my shortcode wasn’t working. The solution is what I had to change in the page.php and then I made some adjustments to the code in the functions.php. The code I placed in the page.php is:

    $home_page_id = 53;
    $home_page = get_page($home_page_id);
    $content_page = $home_page->post_content;
    $content = apply_filters('the_content', $home_page->post_content);
    echo $content;

    And in the functions.php I adjusted the code to:

    function contactus() {
    	$contactus_page_id = 26;
    	$contactus_page = get_page($contactus_page_id);
    	$content_page = $contactus_page->post_content;
    	$content = apply_filters('the_content', $contactus_page->post_content);
    
    	return $content;
    }
    
    add_shortcode('contactuscontent', 'contactus');

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Shortcodes in the functions.php file not working’ is closed to new replies.