Viewing 15 replies - 1 through 15 (of 18 total)
  • Plugin Author WPKube

    (@wpkube)

    Hi @computingforall

    You’re welcome and thank you.

    By default it should be added to all public post types.

    Is the issue that the options show up in the backend but the code you add does not get added to the frontend?

    Or is the issue that the options don’t show up at all?

    Thread Starter computingforall

    (@computingforall)

    Hi,
    Thank you for the prompt response. The options show up in the editor in the backend. I can write the code in the textbox provided for the header and footer, but the code I add does not embed in the html of the published post (public).

    Please note that the codes I write in the header/footer textbox with regular posts get embedded in the html. If the post type is something different (such as a lesson-type), then the added code is not embedded into the published post.

    Thank you.

    Plugin Author WPKube

    (@wpkube)

    Hi @computingforall

    Can you do a quick test with the global options.

    If they don’t get added either then it’s possible that the plugin does not call the WordPress function wp_head() and wp_footer() which are required in themes and it’s what our plugin “hooks into” to output the custom codes.

    In which case I’ll take a look at the LearnPress plugin code and see if they have some hooks available which we can use to output the code.

    Thread Starter computingforall

    (@computingforall)

    Thank you so much! I have just tested with the global options of Embed Code. I placed a test code to embed in the head of all pages globally. The code was embedded everywhere including lessons. That is, the “GLOBAL CODE” part of Embed Code works for all post types including lessons.

    The codes placed in the backend editor of individual lesson posts cannot embed the code in the frontend published html.

    I really appreciate your continuous responses regarding this.

    Thank you.

    Plugin Author WPKube

    (@wpkube)

    Hi @computingforall

    You’re welcome.

    Since the global code works it means that either the WordPress function is_singular() returns false in this case or the get_the_ID() function returns the wrong ID.

    is_singular() is used to check if the currently shown page is a “single page” for one of the public post types.

    If the previous one returns true then get_the_ID() is used to get the ID of the current page and then check if there are header/footer codes associated with that ID.

    One (or both) of those fails for some reason.

    I’ll set up LearnPress on my WP install and test it out. Hopefully there’s a solution.

    Thread Starter computingforall

    (@computingforall)

    I see. Thank you for explaining. I also hope that there is a solution.

    I appreciate that you are willing to take the time to set up LearnPress and and run tests.

    Plugin Author WPKube

    (@wpkube)

    Hi @computingforall

    I installed LearnPress with their sample content. I then added custom code (our plugin options) which worked fine on the course.

    The code I added as a test is <script>alert('test')</script> which trigger an alert prompt in the browser when the page loads.

    Can you try that code as well?

    Thread Starter computingforall

    (@computingforall)

    That is an interesting finding. It still does not work on the lessons pages for me. The alert with the test message shows up on other pages though.

    This makes me think that the issue is probably with the theme (Eduma by Thimpress) I am using. I will contact the theme developers.

    I really appreciate that you looked deep inside the problem. Many many thanks!

    Plugin Author WPKube

    (@wpkube)

    Hi @computingforall

    You’re welcome.

    Or it might be a conflict with another plugin.

    There’s some code modification related tests we can do which will make it easy to figure out what exactly happens. Do you have experience with editing PHP files? It won’t be anything complicated.

    Thread Starter computingforall

    (@computingforall)

    Hi @wpkube
    I did not think about another plugin being in conflict. That is a good point.

    I do not have much experience with PHP, but I have worked with basic PHP codes from time to time. I am up for the test. Please let me know how to proceed.

    Thank you.

    Plugin Author WPKube

    (@wpkube)

    Hi @computingforall

    The file is: wp-content/plugins/embed-code/includes/class-ec-plugin.php

    On line 73 you should see:

    public function output_head_code() {

    That’s the start of the function that handles the output of the head code.

    Below that, on lines 80-82 you should see:

    if ( is_singular( $this->get_enabled_post_types() ) ) {
    	echo $this->wrap_line_breaks( get_post_meta( get_the_ID(), '_ec_head_code', true ) );
    }

    That’s the part of the code that checks if we’re currently on a single post page of a public post type and if we are output the head code for that post.

    The first test is to simply get rid of that check. So those 3 lines become this:

    echo $this->wrap_line_breaks( get_post_meta( get_the_ID(), '_ec_head_code', true ) );

    After making that change try visiting the course and let me know if the head code gets added.

    After the test you can put back the original code.

    Thread Starter computingforall

    (@computingforall)

    Hi @wpkube
    I have done the test. There was no impact. Lesson posts still do not have the head code. Other posts contain the intended head code when added. That is, there is no impact with the change.

    I have put back the original code in the function output_head_code function.

    Please let me know what to do next.

    Thanks once again for agreeing to run the tests.

    Thread Starter computingforall

    (@computingforall)

    Hi @wpkube
    By the way, a sample lesson-post where I am trying to add head code is: https://computing4all.com/courses/introductory-data-science/lessons/what-is-a-vector/

    Could it be the case that the backend tries to add the code to another url, such as https://computing4all.com/lessons/what-is-a-vector/
    (where the part “courses/introductory-data-science” is missing)

    Previously, the Eduma theme support added a function to correct the URLS of the sitemap generated by Yoast. The function was added to the functions.php file of the Child theme of Eduma. Before the addition of the function, Yoast wast generating sitemaps containing urls without the “courses/introductory-data-science” part.

    That is why I am saying, may be embed-code is adding to https://computing4all.com/lessons/what-is-a-vector/, instead of https://computing4all.com/courses/introductory-data-science/lessons/what-is-a-vector/

    Is it possible to check, from the embed-code, in which url it is trying to add the head code?

    Thank you.

    Plugin Author WPKube

    (@wpkube)

    Hi @computingforall

    Ok, so it’s definitely not the if statement which brings us back to the other function I mentioned, get_the_ID()

    Just above the if statement add echo 'the id is' . get_the_ID();

    So that whole section looks like this:

    echo 'the id is ' . get_the_ID();
    if ( is_singular( $this->get_enabled_post_types() ) ) {
    	echo $this->wrap_line_breaks( get_post_meta( get_the_ID(), '_ec_head_code', true ) );
    }

    You won’t see anything displayed on the page itself since that will be part of the <head> but if you look at the source code (right click somewhere on the page and then select “view source”) and do a search for “the id is” you will see it.

    It will say something like “the id is 134”. That will be the numeric ID of the post it’s trying to get the codes for.

    Is that ID the same as the one you see when you go to edit the course in the WP admin? You can see the ID in the URL, it’s like wp-admin/post.php?post=134&action=edit&tab=course_settings

    Thread Starter computingforall

    (@computingforall)

    Hi @wpkube
    Your guess is correct. That is, get_the_ID() is returning an incorrect ID.

    Here is what is happening — the lesson posts are returning the course page’s ID under which the lessons are created.

    If I embed anything on the course page, then all lesson posts under that course contain the course page’s embedded code.

    If I try to embed any code to a lesson, it is not going anywhere (not even to the course page.)

    In the editor URLs (such as, wp-admin/post.php?post=5216&action=edit ) , the lessons have their own post IDs, which are different from the course post ID.

    When the lesson is loaded in the browser, the post ID printed on the html source (due to the echo command) shows the course page’s ID.

    If you kindly decide to proceed with further tests, is it alright to send you the function that fixes the urls for the sitemap, written on my functions.php file? I think the function has some hints on the ID-related issue we currently have. My email address is computeadmin (the at the rate of symbol) computing4all (the dot) com. I am not asking for your email address for privacy reasons. If you kindly send me an email, I will reply with the sitemap-related function. I am just taking caution because I do not know how serious the code is.

    It seems the issue was never with embed code plug-in. I completely understand if you would like to close the thread because the problem has been detected.

    I highly appreciate all the communications and systematic tests you came up with.

    Thank you.`

Viewing 15 replies - 1 through 15 (of 18 total)
  • The topic ‘Can I make it work on unconventional post type?’ is closed to new replies.